-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram7.cpp
98 lines (98 loc) · 1.5 KB
/
Program7.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
/* Q: Menu driven Program to demonstrate the implementation of various operations on a Circular queue .*/
#include<iostream>
using namespace std;
class circularQueue
{
public:
int size,a[20],value;
static int front,rear;
circularQueue()
{
cout<<"enter size of array : ";
cin>>size;
}
void push()
{
cout<<"enter the element : ";
cin>>value;
if((front==0 && rear==size-1) || (rear==front-1))
cout<<"Queue overflow"<<endl;
else
{
if(front==-1)
{
front=rear=0;
}
else if(rear==size)
{
rear=0;
}
else
rear++;
a[rear]=value;
}
}
void pop()
{
if(front==-1)
cout<<"Queue Underflow"<<endl;
else
{
if(front==rear)
front=rear=-1;
else if(front==size)
front=0;
else
front++;
}
}
void pip()
{
if(rear<front)
{
for(int i=front;i<size;i++)
cout<<a[i]<<" ";
for(int i=0;i<=rear;i++)
cout<<a[i]<<" ";
}
else if(rear>front)
for(int i=front;i<=rear;i++)
cout<<a[i]<<" ";
}
};
int circularQueue::front=-1;
int circularQueue::rear=-1;
int main()
{
int c;
circularQueue q;
cout<<" 1.Push \n 2.Pop \n 3.Pip \n 4.Exit"<<endl;
while(1)
{
cout<<endl<<"enter the choice : ";
cin>>c;
switch(c)
{
case 1:
{
q.push();
break;
}
case 2:
{
q.pop();
break;
}
case 3:
{
q.pip();
break;
}
case 4:
{
exit(0);
}
}
}
return 0;
}