-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue.cpp
More file actions
109 lines (89 loc) · 1.9 KB
/
Copy pathqueue.cpp
File metadata and controls
109 lines (89 loc) · 1.9 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include <iostream>
using namespace std;
#define max 5
class queue
{
private:
int arr[max];
int front; //pointer use as i in arr
int rear;
public:
queue();
bool empty();
int enqueue(int top); // add at back
void dequeue(); //remove front
bool isfull();
int peak();
int back();
void display();
};
queue::queue()
{
front = -1;
rear = -1;
}
bool queue::empty()
{
if(front == -1 and rear == -1)
{
return 1;
}
else return 0;
}
bool queue::isfull()
{
if(rear == max)
{
return 1;
}
else return 0;
}
int queue::enqueue(int num)
{
rear++;
if(front == -1){ front = 0; }
return arr[rear] = num;
}
void queue::dequeue()
{
front++;
}
int queue::peak()
{
return arr[front];
}
int queue::back()
{
return arr[rear];
}
void queue::display()
{
for(int j = 0; j <= rear; j++)
{
cout << arr[j] << ' ';
}
}
int main() {
queue q1;
cout << (q1.empty() == true ? "is empty : true\n" : "is empty : false\n");
cout << "peek : " << q1.peak() << endl ;
q1.enqueue(10);
cout << "enqueued 10 " << endl;
cout << "front : " << q1.peak() << endl ;
cout << "back : " << q1.back() << endl << endl;
q1.enqueue(20);
cout << "enqueued 20 " << endl;
cout << "front : " << q1.peak() << endl ;
cout << "back : " << q1.back() << endl << endl;
q1.enqueue(30);
cout << "enqueued 30 " << endl;
cout << "front : " << q1.peak() << endl ;
cout << "back : " << q1.back() << endl << endl;
q1.dequeue();
cout << "dequeued (pop front) " << endl;
cout << "front : " << q1.peak() << endl ;
cout << "back : " << q1.back() << endl << endl;
// cout << (s1.empty() == true ? "is empty : true\n" : "is empty : false\n");
q1.display();
}
//next make template so i can use it with string too