Create and Read LINKED LIST

#include <stdio.h>
#include <stdlib.h>

struct node
 {
 int data;
 struct node *addr;
 };

void generateData(struct node *head)
 {
 struct node *current = NULL;
 for(int i=0; i<5; i++)
 {
 current = (struct node *)malloc(sizeof(struct node));
 current->data=i;
 current->addr=head;
 head=current;
 }

while(head)
 {
 printf("%d \n", head->data);
 head=head->addr;
 }

}
 int main()
 {
 struct node *head = NULL;
 generateData(head);
 return 0;
 }

 

Advertisements