-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue.cpp
More file actions
73 lines (68 loc) · 1.07 KB
/
Copy pathqueue.cpp
File metadata and controls
73 lines (68 loc) · 1.07 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
#include <iostream>
using namespace std;
struct queue
{
int front;
int rear;
int arr[100];
};
bool isfull(queue &q)
{
return q.rear == 100 - 1;
}
bool isEmpty(queue &q)
{
return q.front == -1;
}
void Equeue(queue &q, int x)
{
if (isfull(q))
{
cout << "the queue is full :";
return;
}
if (q.front == -1)
q.front++;
q.arr[++q.rear] = x;
cout << q.rear;
}
void Dequeue(queue &q)
{
if (isEmpty(q))
{
cout << "the queue is empty ";
return;
}
if (q.front == q.rear)
{
q.front = q.rear = -1;
return;
}
q.front++;
}
int getSize(queue &q)
{
if (isEmpty(q))
{
return 0;
}
return (q.rear - q.front + 1);
}
void display(queue &q)
{
cout << "the list of the queue is :\n";
int front = q.front;
while ((q.front != q.rear) || q.rear != 0)
{
cout << q.arr[front] << ' ';
}
}
int main()
{
queue q;
q.front = -1;
q.rear = -1;
Equeue(q, 1);
Equeue(q, 2);
cout << "the size of queue is: " << getSize()
}