-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue.cpp
More file actions
75 lines (62 loc) · 955 Bytes
/
Copy pathqueue.cpp
File metadata and controls
75 lines (62 loc) · 955 Bytes
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
#include<iostream>
using namespace std;
class Queue{
int *arr;
int s;
int top;
public:
Queue(int a){
top = 0;
arr = new int[a];
s = a;
}
void push(int d);
int pop();
void print();
};
void Queue::push(int d){
if (top == s) {
cout << "Queue is full" << endl;
}
else {
arr[top] = d;
top++;
}
}
int Queue::pop(){
if (top == 0) {
cout << "Queue is empty" << endl;
return NULL;
}
else
{
int temp = arr[0];
for (int i = 0; i <= top; i++)
{
arr[i] = arr[i + 1];
}
top--;
return temp;
}
}
void Queue::print(){
for (int i = 0; i<top; i++)
{
cout << arr[i] << endl;
}
}
int main(){
Queue ob(4);
ob.push(5);
ob.push(2);
ob.push(7);
ob.push(9);
ob.push(9);
ob.print();
cout << ob.pop() << endl;
cout << ob.pop() << endl;
cout << ob.pop() << endl;
cout << ob.pop() << endl;
cout << ob.pop() << endl;
return 0;
}