I trying to get the hang of link list, but very time a write one i fail miserably...
struct node
{
int data;
node *next;
};
int main()
{
node *head = new node;
head = NULL;
node *temp = head;
//node 1
temp->data = 1;
temp->next = NULL;
temp = temp->next;
//node 2
temp->data = 2;
temp->next = NULL;
//traverse
temp = head;
while(temp != NULL)
{
cout << temp->data;
temp = temp->next;
}
return 0;
}
please tell me what i'm doing wrong.