-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueue.cpp
82 lines (51 loc) · 1.19 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
82
#include <iostream>
#include <vector>
using namespace std;
#define MAX 1000
class Queue {
public:
int rear_value;
int a[MAX]; // Maximum size of Queue
Queue() { rear_value = -1; }
bool enqueue(int x){
if(rear_value < MAX){
rear_value++;
a[rear_value] = x;
return true;
}
return false;
}
int dequeue(){
if(rear_value > -1){
int curr = a[0];
// int * array = new int [MAX];
// for(int i = 0; i < rear_value; i++){
// array[i] = a[i+1];
// cout<<"This "<< i << " " <<array[i]<<endl;
// }
// array = a;
for(int i = 0; i < rear_value; i++){
a[i] = a[i+1];
}
a[rear_value] = '\0';
return curr;
}
return 0;
};
int front(){
if(rear_value > -1) return a[0];
return 0;
};
int rear(){
if(rear_value > -1) return a[rear_value];
return 0;
}
};
int main(){
Queue myqueue;
myqueue.enqueue(10);
// for(int i = 0; i <= myqueue.rear_value; i++){
// cout<< myqueue.a[i]<< endl;
// }
return 0;
};