Originally Posted by
Salem
Your basic list operation to visit every node is.
Node *temp = head;
while ( temp ) temp = temp->next;
Code:
#include<stdio.h>#include<stdlib.h>
struct Node
{
int data;
struct Node *next;
};
int main()
{
struct Node* head = NULL;
struct Node* second = NULL;
struct Node* third = NULL;
struct Node *temp = head;
head = (struct Node*)malloc(sizeof(struct Node));
second = (struct Node*)malloc(sizeof(struct Node));
third = (struct Node*)malloc(sizeof(struct Node));
head->data = 1; //assign data in first node
head->next = second; // Link first node with second
second->data = 2; //assign data to second node
second->next = third;
third->data = 3; //assign data to third node
third->next = NULL;
while ( temp )
printf("%d\n", temp->next);
temp = temp->next;
return 0;
}
It give following results
72196967219696
7219696
7219696
7219696
7219696
7219696
7219696
7219696
7219696
7219696
7219696
7219696
7219696
7219696
7219696
7219696
7219696
7219696
7219696