-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueue.h
71 lines (60 loc) · 879 Bytes
/
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
66
67
68
69
70
71
#ifndef queue_H
#define queue_H
template<class T>
class queue
{
struct Node
{
T data;
Node *next;
};
private:
struct Node* r;
struct Node* f;
int sz = 0;
public:
queue()
{
r = NULL;
f = NULL;
}
void push(T value)
{
++sz;
Node *temp = new Node;
temp->data = value;
temp->next = NULL;
if(r!=NULL)r->next = temp;
r = temp;
if(sz == 1)
{
f = r;
}
}
void pop()
{
--sz;
Node* temp;
temp= f;
f = f->next;
temp->next = NULL;
delete temp;
}
T front()
{
return (f->data);
}
T rear()
{
return (r->data);
}
T size()
{
return sz;
}
bool empty()
{
return (sz == 0);
}
};
#endif