-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue_Normal_Implementation.cpp
More file actions
88 lines (74 loc) · 1.09 KB
/
Copy pathQueue_Normal_Implementation.cpp
File metadata and controls
88 lines (74 loc) · 1.09 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
#include<iostream>
using namespace std;
#define N 5
char queue[N];
int front =-1;
int rear = -1;
void push(char ch)
{
if(front==0 && rear== N-1 || front == rear+1)
{
cout<<"overflow"<<endl;
exit(1);
}
if(front==-1 && rear==-1)
{
front++;
rear++;
}
else if(rear==N-1)
{
rear=0;
}
else
{
rear++;
}
queue[rear]=ch;
}
void Qtraverse()
{
for(int i = front;;)
{
cout<<queue[i]<<" ";
if(i==rear)
{
break;
}
if(i==N-1)
{
i=0;
}
else
{
i++;
}
}
cout<<endl;
}
void pop()
{
cout<<queue[front]<<" is deleted"<<endl;
if(front==N-1)
{
front=0;
}
else if(front==rear)
{
front=-1;
rear=-1;
}
else
front++;
}
int main()
{
push('A');
push('B');
push('C');
Qtraverse();
pop();
pop();
Qtraverse();
return 0;
}