-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue_array.cpp
More file actions
69 lines (55 loc) · 1.11 KB
/
Copy pathqueue_array.cpp
File metadata and controls
69 lines (55 loc) · 1.11 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
/*
* 2019.6.28
* data structure implementation - queue_array
*/
#include <iostream>
using namespace std;
class QueueArr {
public:
int q_size, capacity;
int *queue;
QueueArr() {
q_size = 0;
capacity = 8;
queue = new int[capacity];
}
~QueueArr() {
delete[] queue;
queue = NULL;
}
void push(int value) {
if (q_size == capacity) {
capacity *= 2;
int *temp = new int[capacity];
for (int i = 0; i < capacity / 2; i++) {
temp[i] = queue[i];
}
temp = queue;
delete[] queue;
queue = NULL;
}
queue[q_size++] = value;
}
int front() {
if (q_size == 0) return -1;
return queue[q_size - 1];
}
void pop() {
if (q_size == 0) return;
q_size--;
}
bool empty() {
return !q_size;
}
int size() {
return q_size;
}
};
int main() {
int input;
cin >> input;
int *arr = new int[input];
for (int i = 0; i < input; i++) {
cin >> arr[i];
}
}