LinkedList in C

#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;
 head = (struct node*)malloc(sizeof(struct node));
 second = (struct node*)malloc(sizeof(struct node));
 third = (struct node*)malloc(sizeof(struct node));
 head->data = 1;
 head->next = second;
 second -> data = 2;
 second -> next = third;
 third -> data =3;
 third -> next = NULL;
 print(head);
 return 0;
}
void print(struct node *n)
{
 while(n!= NULL)
 {
 printf("%d",n->data);
 n = n ->next;
 }
}

Comments

Popular posts from this blog

Three mislabeled Jar

Difference between Macro And function