-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueue using rear n front.cpp
75 lines (73 loc) · 1.38 KB
/
queue using rear n front.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include<iostream>
using namespace std;
#define size 5 //Maximum Size of Queue
int Queue[size];
int rear=-1,front=-1,item;
int main()
{
int choice;
void Insert();
void Delete();
void Display();
for(;;) //Infinite Loop.
{
cout<<"\n\n\n\n---------- QUEUE ---------- \n";
cout<<"\nMain Menu\n\n1. Insert\n2. Delete\n3. Display\n4. Exit\n\nEnter your choice : ";
cin>>choice;
switch(choice)
{
case 1:
Insert();
break;
case 2:
Delete();
break;
case 3:
Display();break;
case 4:
return 0; //Exit
default:
cout<<"\nWrong Input";
}
}
}
void Display() //Display's the Element of Queue.
{ int i;
if(front==-1)
cout<<"\nQueue is Empty\n";
else
for(i=front;i<=rear;i++)
cout<<endl<<"Queue["<<i<<"]="<<Queue[i];
}
void Insert() //Insert a New Element in Queue.
{
if(rear==size-1)
cout<<"\nOverflow\n";
else
{
if(rear==-1 && front==-1)
rear=0,front=0;
else
rear++;
cout<<"\nEnter the Element you want to Insert : ";
cin>>item;
Queue[rear]=item;
cout<<endl<<item<<" is Inserted.\n";
Display();
}
}
void Delete() //Delete Element from Queue.
{
if(front==-1)
cout<<"\nUnderflow\n";
else
{
item=Queue[front];
if(front==rear)
front=-1,rear=-1;
else
front=front++;
cout<<endl<<item<<" is Deleted.\n";
Display();
}
}