I write this code to automatically gets values and put them in a linked list but it just maintain first one and replace any new one in second node and doesn't make third, forth or ... nodes.
#include <iostream>
using namespace std;
struct node
{
int a;
struct node *next;
}zero;
node *first = NULL;
int main()
{
int t;
for (int i = 0;i < 10;i++)
{
node *n = first;
cin >> t;
if (first == NULL)
{
node temp;
temp.a = t;
first = &temp;
temp.next = NULL;
}
else
{
while ((*n).next != NULL)
{
n = (*n).next;
}
node tt;
tt.a = t;
(*n).next = &tt;
tt.next = NULL;
}
}
}
I inserted 28. my first node data=28. I inserted 57. my second node data=57. I inserted 120. my second node data=120. ...