Professional Documents
Culture Documents
Insert at End of Link List
Insert at End of Link List
Insert at End of Link List
h> struct node { int data; struct node *link; }; void insert_end (); void display(); void main() { int i,ch; struct node *p; clrscr(); p=NULL; printf("enter your choice 1 for insert and 2 for display"); scanf("%d", &ch); if (ch==1) { printf("enter the number you want to insert"); for(i=0;i<5;i++) { scanf("%d",&i); insert_end( &p, i); //display(p); } display(p); } else display(p); getch(); } void insert_end( struct node **q, int num) { struct node *temp, *r; if (*q==NULL) { temp= (struct node *) malloc (sizeof (struct node)); temp -> data = num; temp ->link = NULL; *q= temp; } else { temp = *q; while(temp->link != NULL) { temp= temp->link; } r= (struct node *)malloc (sizeof(struct node)); r->data= num; r-> link= NULL; temp-> link=r; } } void display(struct node *q) {