Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Push & Pop in a Queue implemented as an array
- #include<iostream.h>
- #include<conio.h>
- #include<stdio.h>
- void main()
- {clrscr();
- int rear=-1, front=-1, Size=5;
- void InsertQ(int Queue[])
- {
- int Insert;
- cout<<"Enter the number you want to insert"<<endl;
- cin>>Insert;
- if(rear==Size-1)
- {
- cout<<"Overflow"<<endl;
- }
- else if(rear==-1)
- {
- rear=front=0;
- Queue[0]=Insert;
- }
- else
- {
- rear++;
- Queue[rear]=Insert;
- }
- }
- void DeleteQ(int Queue[])
- {
- if(front==-1)
- {
- cout<<"Underflow"<<endl;
- }
- else
- if(front==rear)
- {
- cout<<Queue[front]<<" Was Deleted"<<endl;
- front=rear=-1;
- }
- else
- {
- cout<<Queue[front]<<" Was Deleted"<<endl;
- front++;
- }
- }
- void Display(int Queue[])
- {
- int i;
- cout<<"The Queue is: ";
- for(i=front;i<=rear;i++)
- {
- cout<<Queue[i]<<" ";
- }
- }
- int main()
- {
- int Q[50],o1;
- char o2;
- do
- {
- cout<<"MENU"<<endl;
- cout<<"1. Insert \n2. Delete \n3. Display \n4. Exit"<<endl;
- cin>>o1;
- switch(o1)
- {
- case 1:
- InsertQ(Q);
- break;
- case 2:
- DeleteQ(Q);
- break;
- case 3:
- Display(Q);
- break;
- case 4:
- exit(0);
- default:
- cout<<"Please Enter A Valid Option"<<endl;
- break;
- }
- cout<<"Would You Like to Continue?(Y/N)"<<endl;
- cin>>o2;
- }while(o2=='Y' || o2=='y');
- }
- /*
- MENU
- 1. Insert
- 2. Delete
- 3. Display
- 4. Exit
- 1
- Enter the number you want to insert
- 2
- Would You Like to Continue?(Y/N)
- Y
- MENU
- 1. Insert
- 2. Delete
- 3. Display
- 4. Exit
- 1
- Enter the number you want to insert
- 3
- Would You Like to Continue?(Y/N)
- Y
- MENU
- 1. Insert
- 2. Delete
- 3. Display
- 4. Exit
- 3
- The Queue is: 2 3
- Would You Like to Continue?(Y/N)
- Y
- MENU
- 1. Insert
- 2. Delete
- 3. Display
- 4. Exit
- 2
- 3 Was Deleted
- Would You Like to Continue?(Y/N)
- N
- */
Add Comment
Please, Sign In to add comment