-
Notifications
You must be signed in to change notification settings - Fork 0
/
Queue.h
65 lines (54 loc) · 1 KB
/
Queue.h
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
#ifndef QUEUE_H
#define QUEUE_H
#ifndef NULL
#define NULL 0
#endif
const int MAX = 200;
template<class T> class Queue
{
public:
int front;
int rear;
int size; //Free to define (recommand 100 or 200)
T* val;
Queue() {
size = MAX;
val = new T[size];
front = 0;
rear = 0;
}
~Queue()
{
delete[] val;
}
void push(T value) {
// input data
rear = (rear + 1) % MAX;
val[rear] = value;
}
void pop() {
//Change Front
front = (front + 1) % MAX;
}
bool empty() {
//Check its empty or not
if (front == rear)
return true;
else
return false;
}
bool isFull() {
//Check queue is full or not
if (rear + 1 == size)
return true;
else
return false;
}
T getfront() {
return val[(front + 1) % MAX];
}
int qsize() {
return (rear - front + MAX) % MAX;
}
};
#endif