forked from pradbajaj/bothoven
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueueDynamic.h
67 lines (61 loc) · 1015 Bytes
/
QueueDynamic.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
#include<iostream>
using namespace std;
int choice;
struct Node
{
int data;
struct Node* next;
};
struct Queue
{
struct Node *head, *tail;
};
struct Node * NewNode()
{
struct Node *temp = new struct Node;
temp->next=NULL;
return temp;
}
struct Queue * NewQueue()
{
struct Queue *Q = new struct Queue;
Q->head=NULL;
Q->tail=NULL;
return Q;
}
void EnQueue(struct Queue *Q, int data)
{
struct Node * temp= NewNode();
temp->data=data;
if(Q->head==NULL && Q->tail==NULL)
{
Q->head=temp;
Q->tail=temp;
return;
}
Q->tail->next=temp;
Q->tail=temp;
}
int DeQueue(struct Queue *Q)
{
if(Q->head==NULL && Q->tail==NULL)
{
return -1;
}
struct Node *temp = Q->head;
int data = temp->data;
Q->head=Q->head->next;
if(Q->head==NULL)
Q->tail=NULL;
delete temp;
return data;
}
void EmptyQueue(struct Queue *Q)
{
while(Q->head!=NULL)
DeQueue(Q);
}
bool IsEmpty(struct Queue *Q)
{
return (Q->head==NULL) ? true : false ;
}