-
Notifications
You must be signed in to change notification settings - Fork 5
/
queue_using_LL.cpp
56 lines (45 loc) · 914 Bytes
/
queue_using_LL.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
emplate<typename T>
class Queue {
Node<T> *head,*last;
int size;
public :
Queue() {
last=head=NULL;
size=0;
}
void enqueue(T data) {
Node<T> *newnode= new Node<T>(data);
if(head==NULL)
{
head=last=newnode;
size++;
}
else
{
last->next=newnode;
last=newnode;
size++;
}
}
int getSize() {
return size;
}
bool isEmpty() {
return size==0;
}
T dequeue() {
// Return 0 if queue is empty
if(size==0)
return 0;
T ans=head->data;
Node<T> *p=head;
head=head->next;
delete p;
size--;
return ans;
}
T front() {
// Return 0 if queue is empty
return head->data;
}
};