-
Notifications
You must be signed in to change notification settings - Fork 0
/
Queue.cpp
81 lines (74 loc) · 1.45 KB
/
Queue.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
#include <iostream>
#include <cstdlib>
#include <queue>
using namespace std;
#define MAX_SIZE 10
int queue1[MAX_SIZE];
int queue2[MAX_SIZE];
int front1 = -1;
int rear1 = -1;
int front2 = -1;
int rear2 = -1;
void enq(int *queue, int &front, int &rear, int x)
{
if (rear == MAX_SIZE - 1)
{
cout << "Its full" << endl;
}
else if (front == -1)
{
front = rear = 0;
}
else
{
rear++;
}
queue[rear] = x;
}
void delq(int *queue, int &front, int &rear)
{
if (front == -1)
{
cout << "Its empty" << endl;
}
else if (front == rear)
{
front = -1;
rear = -1;
}
else
{
front++;
}
}
void display(int *queue, int front, int rear)
{
if (front == -1)
cout << "Its empty";
else{
for (int i = front; i <= rear; i++)
{
cout << queue[i] << " ";
}
}
cout << endl;
}
// void enqueueF(queue<int> &p, int x)
// {
// p.push(x);
// }
int main()
{
enq(queue1, front1, rear1, 10);
enq(queue2, front2, rear2, 50);
enq(queue1, front1, rear1, 20);
enq(queue2, front2, rear2, 60);
enq(queue1, front1, rear1, 30);
enq(queue2, front2, rear2, 70);
delq(queue1, front1, rear1);
delq(queue2, front2, rear2);
display(queue1, front1, rear1);
display(queue2, front2, rear2);
return 0;
}
// queue<int> p;