-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
131 lines (122 loc) · 2.38 KB
/
main.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include <iostream>
using namespace std;
class Queue {
int j;
int front;
int rear;
public:
int a[5];
Queue()
{
j=5;
front=-1;
rear=-1;
}
void enqueue();
void dequeue();
void frontt();
void display();
};
void Queue::frontt()
{
cout<<"FRONT = "<<a[front]<<endl;
}
void Queue::enqueue()
{
int ele;
cout<<"Enter element to be added "<<endl;
cin>>ele;
if(front==0&&rear==4)
cout<<"Queue full \n";
else if((front==rear+1)&&(j!=0))
cout<<"Queue full \n";
else
{
if(rear==-1)
{
front=rear=0;
a[0]=ele;
}
else
rear=(rear+1)%5;
a[rear]=ele;
}
if(j==0)
j=1;
}
void Queue::dequeue()
{
int temp;
if(j==0)
cout<<"Queue Empty \n";
else
{
if((front==rear)&&(front!=-1))
j=0;
if(front==-1)
cout<<"Queue empty \n";
else
{
temp=a[front];
front=(front+1)%5;
}
cout<<"DELETED ITEM IS "<<temp<<"\n";
}
}
void Queue::display()
{
int i;
if(j==0)
cout<<"QUEUE EMPTY \n";
else if(front==-1)
cout<<"Queue Empty \n";
else
{
cout<<"THE RESULTANT QUEUE IS \n";
if(rear>=front)
{
for(i=front;i<=rear;i++)
cout<<a[i]<<endl;
}
else
{
i=front-1;
do
{
i=(i+1)%5;
cout<<a[i]<<endl;
}while(i!=rear);
}
cout<<"\n";
}
}
int main()
{
class Queue a;
int choice;
do
{
cout<<" MENU "<<endl;
cout<<"1. ENQUEUE "<<endl;
cout<<"2. DEQUEUE "<<endl;
cout<<"3. FRONT "<<endl;
cout<<"4. DISPLAY "<<endl;
cout<<"5. EXIT "<<endl;
cout<<"Enter your choice ";
cin>>choice;
switch(choice)
{
case 1:a.enqueue();
break;
case 2:a.dequeue();
break;
case 3:a.frontt();
break;
case 4:a.display();
break;
case 5:break;
default:break;
}
}while(choice!=5);
return 0;
}