Repository navigation
Expand file tree
/
Copy pathqueue.h
More file actions
92 lines (82 loc) · 1.85 KB
/
Copy pathqueue.h
File metadata and controls
92 lines (82 loc) · 1.85 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using namespace std;
class Node // Queue node for dumping customer data
{
public:
string customerName;
Node* next;
};
Node* front = NULL;
Node* rear = NULL;
bool isEmpty() // function for checking if queue is empty
{
if(front == NULL && rear == NULL)
{
return true;
}
else
{
return false;
}
}
void Enqueue(string name) // functiong for putting customer in queue w.r.t name
{
Node* new_node = new Node();
new_node->customerName = name; // assigning data
new_node->next = NULL;
if(front == NULL) // if the current customer is first in queue
{
front = new_node;
rear = new_node;
return;
}
else // tackling links if new customer joins queue
{
rear->next = new_node;
rear = new_node;
}
}
void Dequeue() // function for dequeue front cutomer who came first
{
Node *temp = front;
if(front == NULL) // if no customer is present in queue
{
cout<<"\nQueue Underflow ! The Queue is Empty.\n"<<endl;
}
else if(front == rear) // if only customer left
{
front = rear = NULL;
}
else // tackling links in this body
{
front = front->next;
}
delete(temp); // free meomry for previous customer
}
void displayFront() // prints name of customer at front of queue
{
if(isEmpty())
{
cout<<"The Queue is Empty\n";
return;
}
else
{
cout<<"The Element at front is: "<<front->customerName<<"\n";
}
}
void displayQueue() // prints all customers names present in queue
{
if(isEmpty())
{
cout<<"The Queue is Empty\n";
}
else
{
Node* temp = front;
while(temp != NULL)
{
cout<<"\t"<<temp->customerName <<"\t "<<endl;
temp = temp->next;
}
}
}