i want to remove the last item of the linked list..my 'rmlast' function does this
but i couldnt do that please help
Code:#include<stdio.h> #include<conio.h> #include<malloc.h> #define NULL 0 struct linked_list { int num; struct linked_list *next; }; typedef struct linked_list node; void main() { void create(node *); void print(node *); node *rmfirst(node *); node *addfirst(node *); void rmlast(node *); clrscr(); node *head; void create(node *p); void print(node *p); head=(node *)malloc(sizeof(node)); create(head); printf("\n-----------------------------------------------------\n"); print(head); printf("\n-----------------------------------------------------\n"); head=rmfirst(head); printf("THE LINKED LIST AFTER REMOVING THE FIRST ITEM IS\n"); printf("\n-----------------------------------------------------\n"); print(head); printf("\n-----------------------------------------------------\n"); head=addfirst(head); printf("\n-----------------------------------------------------\n"); print(head); printf("\n-----------------------------------------------------\n"); printf("\nTHE LIST AFTER REMOVING THE LAST ITEM"); head=rmlast(head); print(head); getch(); } void create(node *l) { printf("\nENTER THE NUMBER(enter 999 to end): "); scanf("%d",&l->num); if(l->num==999) { l->next=NULL; } else { l->next=(node *)malloc(sizeof(node)); create(l->next); } return; } void print(node *list) { if(list->next!=NULL) { printf("%d-->",list->num); print(list->next); } return; } node *rmfirst(node *list) { node *m; m=list->next; list=m; return(list); } node *addfirst(node *list) { node *p; printf("\nEnter the number to be inserted"); scanf("%d",&p->num); p->next=list; list=p; return(list); } void rmlast(node *list) { node *p; p=list; if(p->next->next==NULL) { p->next=NULL; } rmlast(p->next); return; }