forked from namishkhanna/hacktoberfest2020
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCircularQueue.cpp
More file actions
95 lines (76 loc) · 1.58 KB
/
CircularQueue.cpp
File metadata and controls
95 lines (76 loc) · 1.58 KB
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
#include<iostream.h>;
#include<conio.h>;
int arr[10],i,front=-1,rear=-1,size;
void ins()
{ if((front==0&&rear==size-1)||(front==rear+1))
{ cout<<"\nQueue overflow";
return; }
if(front==-1)
{ front=rear=0; }
else
{ if(rear==size-1)
rear=0;
else
rear=rear+1; }
cout<<"\nEnter element:";
cin>>arr[rear];
cout<<arr[rear]<<" is inserted\n";
}
void del()
{ if(front==-1)
{ cout<<"\nQueue is empty";
return; }
cout<<arr[front]<<" is deleted";
if(front==rear)
{ front=rear=-1; }
else
{ if(front==size-1)
front=0;
else
front++; }
}
void disp()
{ int ftemp=front,rtemp=rear;
if(front==-1)
{ cout<<"\nQueue is empty";
return; }
cout<<"\nThe elements:";
if(ftemp<=rtemp)
while(ftemp<=rtemp)
{ cout<<arr[ftemp]<<" ";
ftemp++; }
else
{ while(ftemp<=size-1)
{ cout<<arr[ftemp]<<" ";
ftemp++; }
ftemp=0;
while(ftemp<=rtemp)
{ cout<<arr[ftemp]<<" ";
ftemp++; }
}
cout<<endl;
}
void main()
{ clrscr();
char ch,ans;
cout<<"\nEnter size:";
cin>>size;
do
{ clrscr();
cout<<"\n\tMENU\nA.Insert\nB.Delete\nC.Display";
cout<<"\nEnter your choice(A/B/C):";
cin>>ch;
switch(ch)
{ case 'A':
case 'a':ins(); break;
case 'B':
case 'b':del(); break;
case 'C':
case 'c':disp(); break;
default:cout,,"\nWrong choice";
}
cout<<"\nDo you wish to continue(Y/N):";
cin>>ans;
} while(ans=='y'||ans=='Y');
getch();
}