Program:-
Output:-
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice:1
1.INSERT AT END
2.INSERT AT BEGINNING
3.INSERT AT INTERMIDIATE
Enter your choice:1
Enter item:10
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice:1
1.INSERT AT END
2.INSERT AT BEGINNING
3.INSERT AT INTERMIDIATE
Enter your choice:1
Enter item:100
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice:1
1.INSERT AT END
2.INSERT AT BEGINNING
3.INSERT AT INTERMIDIATE
Enter your choice:1
Enter item:20
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice:1
1.INSERT AT END
2.INSERT AT BEGINNING
3.INSERT AT INTERMIDIATE
Enter your choice:1
Enter item:30
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice:3
Your elements are:-
10 100 20 30
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice:2
1.DELETE AT END
2.DELETE AT BEGINNING
3.DELETE AT INTERMIDIATE
Enter your choice:2
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice:3
Your elements are:-
100 20 30
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice:4
Thank You.
Have a Nice day.
#include<stdio.h> #include<malloc.h> struct node{ int info; struct node *next;} *temp, *start=NULL, *ptr, *t; void in(); void inbeg(); void inend(); void inint(); void del(); void delend(); void delbeg(); void delint(); void dis(); void in() //Insert function { int cho; printf("\n1.INSERT AT END\n2.INSERT AT BEGINNING\n3.INSERT AT INTERMIDIATE\n"); printf("Enter your choice:"); scanf("%d",&cho); switch(cho) {case 1: inend(); printf("\n"); break; case 2: inbeg(); printf("\n"); break; case 3: inint(); printf("\n"); break; default:printf("Wrong input\n"); } } void del() //Delete fuction { int cho; printf("\n1.DELETE AT END\n2.DELETE AT BEGINNING\n3.DELETE AT INTERMIDIATE\n"); printf("Enter your choice:"); scanf("%d",&cho); switch(cho) {case 1: delend();break; case 2: delbeg();break; case 3: delint();break; default:printf("Wrong input\n"); } } void dis() //Display function { ptr=start; printf("Your elements are:-\n"); while(ptr!=NULL){ printf("%d ",ptr->info); ptr=ptr->next; } printf("\n"); } void delbeg() //Delete from beginning { ptr=start->next; free(start); start=ptr; } void delint() //Delete from intermediate { int i,loc; printf("Enter location:"); scanf("%d",&loc); for(i=0,ptr=start;i<loc-2;i++){ ptr=ptr->next; } t=ptr->next; ptr->next=t->next; free(t); } void delend() //Delete from end { ptr=start; while(ptr!=temp){ptr=ptr->next;} ptr->next=NULL; free(temp); temp=ptr; } void inbeg() //Insert from beginning { temp=(struct node*)malloc(sizeof(struct node)); printf("Enter item:"); scanf("%d",&temp->info); if(start==NULL){ start=ptr=temp; ptr->next=NULL; } else{ temp->next=start; start=temp; } } void inint() //Insert from intermediate { int i,loc; printf("Enter location:"); scanf("%d",&loc); temp=(struct node*)malloc(sizeof(struct node)); printf("Enter item:"); scanf("%d",&temp->info); for(i=0,ptr=start;i<loc-2;i++){ ptr=ptr->next; } temp->next=ptr->next; ptr->next=temp; } void inend() //Insert from end { temp=(struct node*)malloc(sizeof(struct node)); printf("Enter item:"); scanf("%d",&temp->info); if(start==NULL){ start=ptr=temp; ptr->next=NULL; } else{ ptr->next=temp; ptr=temp; ptr->next=NULL; } } //This program is Developed by MONISH KUMAR BAIRAGI int main() { int cho=123; while(cho<4||cho==123) {printf("1.INSERT\n2.DELETE\n3.DISPLAY\n4.EXIT\n"); printf("Enter your choice:"); scanf("%d",&cho); switch(cho) {case 1: in(); printf("\n"); break; case 2: del(); printf("\n"); break; case 3: dis(); printf("\n"); break; default:printf("\nThank You.\nHave a Nice day.\n"); } } return(0); }
Output:-
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice:1
1.INSERT AT END
2.INSERT AT BEGINNING
3.INSERT AT INTERMIDIATE
Enter your choice:1
Enter item:10
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice:1
1.INSERT AT END
2.INSERT AT BEGINNING
3.INSERT AT INTERMIDIATE
Enter your choice:1
Enter item:100
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice:1
1.INSERT AT END
2.INSERT AT BEGINNING
3.INSERT AT INTERMIDIATE
Enter your choice:1
Enter item:20
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice:1
1.INSERT AT END
2.INSERT AT BEGINNING
3.INSERT AT INTERMIDIATE
Enter your choice:1
Enter item:30
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice:3
Your elements are:-
10 100 20 30
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice:2
1.DELETE AT END
2.DELETE AT BEGINNING
3.DELETE AT INTERMIDIATE
Enter your choice:2
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice:3
Your elements are:-
100 20 30
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter your choice:4
Thank You.
Have a Nice day.
0 Comments