forked from shreyajainn/Data-structures
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cicularqueue.cpp
68 lines (67 loc) · 833 Bytes
/
cicularqueue.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
using namespace std;
#include<iostream>
int arr[20];
int front =-1;
int rear=-1;
int size =5;
void insertion(int s)
{
if(rear==-1&&front==-1)
{
rear=rear+1;
front = front+1;
arr[rear]=s;
}
else if(front==0&&rear==size-1)
{
cout<<"overflow"<<endl;
}
else if(front==rear+1)
{
cout<<"overflow"<<endl;
}
else if(front!=0&&rear==size-1)
{
rear=0;
arr[rear]=s;
}
else
{
rear=rear+1;
arr[rear]=s;
}
}
void deletion()
{
if(rear==-1&&front==-1)
{
cout<<"underflow"<<endl;
}
else if(front==rear)
{
front=rear=-1;
}
else if(front==size-1&&front!=rear)
{
front=0;
}
else
{
front=front+1;
}
}
int main()
{
insertion(5);
insertion(10);
insertion(15);
insertion(20);
insertion(25);
deletion();
while(front!=rear)
{
cout<<arr[front]<<endl;
front=front+1;
}
cout<<arr[front]<<endl;
}