Write a Menu Driven program using C for Dynamic Implementation of Queue For Integers. The Menu Includes -Insert -Delete -Display -Exit.
#include#include #include struct node { int data; struct node *link; }*frount,*rear; void insert(); void del(); void display(); void main() { int ch; clrscr(); frount=NULL; rear=NULL; while(1) { printf("\n 1.Insert."); printf("\n 2.Delete."); printf("\n 3.Display."); printf("\n 4.Exit."); printf("\n Enter Your Choice: "); scanf("%d",&ch); switch(ch) { case 1:insert(); break; case 2:del(); break; case 3:display(); break; case 4:exit(0); default: printf("\n Invalid Choice."); } } } void insert() { struct node *newnode; int ele,i,n; frount=NULL; rear=NULL; printf("\n How Many Element You Want To insert in Queue: "); scanf("%d",&n); for(i=1;i<=n;i++) { newnode=(struct node*)malloc(sizeof(struct node)); if(newnode==NULL) { printf("\n Insufficient Memory."); exit(0); } printf("\n Enter Element %d : ",i); scanf("%d",&ele); newnode->data=ele; newnode->link=NULL; if(frount==NULL) { frount=newnode; rear=newnode; } else { rear->link=newnode; rear=newnode; } } } void del() { struct node *prev; if(frount==NULL) { printf("\n Queue is Full."); } else { prev=frount; printf("\n Deleted Element is : %d ",prev->data); frount=frount->link; free(prev); } } void display() { struct node *temp; temp=frount; if(frount==NULL) { printf("\n Queue is Empty."); return; } printf("\n Elements in The Queue are: "); while(temp!=rear) { printf("\t%d",temp->data); temp=temp->link; } printf("\t%d",temp->data); } /*OUTPUT 1.Insert. 2.Delete. 3.Display. 4.Exit. Enter Your Choice: 1 How Many Element You Want To insert in Queue: 5 Enter Element 1 : 2 Enter Element 2 : 1 Enter Element 3 : 3 Enter Element 4 : 5 Enter Element 5 : 4 1.Insert. 2.Delete. 3.Display. 4.Exit. Enter Your Choice: 3 Elements in The Queue are: 2 1 3 5 4 1.Insert. 2.Delete. 3.Display. 4.Exit. Enter Your Choice: 2 Deleted Element is : 2 1.Insert. 2.Delete. 3.Display. 4.Exit. Enter Your Choice: 3 Elements in The Queue are: 1 3 5 4 1.Insert. 2.Delete. 3.Display. 4.Exit. Enter Your Choice: 2 Deleted Element is : 1 1.Insert. 2.Delete. 3.Display. 4.Exit. Enter Your Choice: 3 Elements in The Queue are: 3 5 4 1.Insert. 2.Delete. 3.Display. 4.Exit. Enter Your Choice: 2 Deleted Element is : 3 1.Insert. 2.Delete. 3.Display. 4.Exit. Enter Your Choice: 3 Elements in The Queue are: 5 4 1.Insert. 2.Delete. 3.Display. 4.Exit. Enter Your Choice: 2 Deleted Element is : 5 1.Insert. 2.Delete. 3.Display. 4.Exit. Enter Your Choice: 3 Elements in The Queue are: 4 1.Insert. 2.Delete. 3.Display. 4.Exit. Enter Your Choice: 2 Deleted Element is : 4 1.Insert. 2.Delete. 3.Display. 4.Exit. Enter Your Choice: 3 Queue is Empty. 1.Insert. 2.Delete. 3.Display. 4.Exit. Enter Your Choice: 4 */
Write a Menu Driven program using C for Dynamic Implementation of Queue For Integers. The Menu Includes -Insert -Delete -Display -Exit.
Reviewed by
on
November 17, 2013
Rating: