Menu driven program using queue | C++ Programming
Tuesday, March 10, 2020//menu driven program using queue
#include<iostream.h>
#include<conio.h>
#include<process.h>
#define size 5
int front=-1,rear=-1;
void insert_Q(int QUEUE[],int ELEMENT,int &front,int &rear)
{ if(rear==size-1)
{ cout<<"\n Queue overflow";
exit(1);
}
rear++;
QUEUE[rear]=ELEMENT;
if(front==-1)
front=0;
}
void delete_Q(int QUEUE[],int &front,int &rear)
{ int value;
value=QUEUE[front];
cout<<"\n Deleted element is:"<<value;
if(front==-1)
{ cout<<"\n Queue underflow";
exit(1);
}
front++;
if(front==rear)
front=rear=-1;
}
void display(int QUEUE[],int &front,int &rear)
{ clrscr();
for( int p=front;p<rear;p++)
cout<<"\t\t"<<QUEUE[p]<<"<--\t";
cout<<QUEUE[rear];
}
void main()
{ clrscr();
int ch,element,queue[20];
l:
cout<<"\n Press 1 for PUSHING"
<<"\n Press 2 for POPING"
<<"\n Press 3 for TRAVERSAL"
<<"\n Press 4 to EXIT";
cin>>ch;
if(ch==4)
{ cout<<"\n THANK YOU";
exit(0);
}
else if(ch==1)
{ cout<<"\n Enter the element to be inserted:";
cin>>element;
insert_Q(queue,element,front,rear);
goto l;
}
else if(ch==2)
{ delete_Q(queue,front,rear);
goto l;
}
else
{ display(queue,front,rear);
goto l;
}
getch();
}
#include<iostream.h>
#include<conio.h>
#include<process.h>
#define size 5
int front=-1,rear=-1;
void insert_Q(int QUEUE[],int ELEMENT,int &front,int &rear)
{ if(rear==size-1)
{ cout<<"\n Queue overflow";
exit(1);
}
rear++;
QUEUE[rear]=ELEMENT;
if(front==-1)
front=0;
}
void delete_Q(int QUEUE[],int &front,int &rear)
{ int value;
value=QUEUE[front];
cout<<"\n Deleted element is:"<<value;
if(front==-1)
{ cout<<"\n Queue underflow";
exit(1);
}
front++;
if(front==rear)
front=rear=-1;
}
void display(int QUEUE[],int &front,int &rear)
{ clrscr();
for( int p=front;p<rear;p++)
cout<<"\t\t"<<QUEUE[p]<<"<--\t";
cout<<QUEUE[rear];
}
void main()
{ clrscr();
int ch,element,queue[20];
l:
cout<<"\n Press 1 for PUSHING"
<<"\n Press 2 for POPING"
<<"\n Press 3 for TRAVERSAL"
<<"\n Press 4 to EXIT";
cin>>ch;
if(ch==4)
{ cout<<"\n THANK YOU";
exit(0);
}
else if(ch==1)
{ cout<<"\n Enter the element to be inserted:";
cin>>element;
insert_Q(queue,element,front,rear);
goto l;
}
else if(ch==2)
{ delete_Q(queue,front,rear);
goto l;
}
else
{ display(queue,front,rear);
goto l;
}
getch();
}
0 Comments