-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue_linked_list.cpp
More file actions
128 lines (102 loc) · 2.06 KB
/
Copy pathQueue_linked_list.cpp
File metadata and controls
128 lines (102 loc) · 2.06 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include <bits/stdc++.h>
using namespace std;
class node
{
public:
int info;
node *next;
};
class Queue
{
private:
node *rear;
node *front;
public:
Queue()
{
rear = NULL;
front = NULL;
}
bool isEmpty()
{
if (front == NULL)
return true;
return false;
}
// Queue cannot be full if it is implemented using linked list.
void enQueue()
{
node *temp = new node; //temp is an object of class node
//temp = new node;
int data;
cout << "\nEnter data to be inserted : ";
cin >> data;
temp->info = data;
temp->next = NULL;
if (front == NULL)
{
front = temp;
rear = temp;
}
else
{
rear->next = temp;
rear = temp;
}
}
void deQueue()
{
int data;
node *temp;
temp = front;
data = front->info; //temp->info
front = front->next;
delete temp;
cout << endl
<< data << " has been deleted." << endl;
}
void display()
{
node *temp;
temp = front;
while (temp != NULL)
{
cout << endl
<< "Data = " << temp->info;
temp = temp->next;
}
}
};
int main()
{
int choice;
Queue queue;
while (1)
{
cout << endl;
cout << "1. To enter data into queue." << endl;
cout << "2. To delete data from queue." << endl;
cout << "3. To display the data." << endl;
cout << "4. TO EXIT." << endl;
cout << "\nENTER YOUR CHOICE... : ";
cin >> choice;
switch (choice)
{
case 1:
queue.enQueue();
break;
case 2:
queue.deQueue();
break;
case 3:
queue.display();
break;
case 4:
exit(0);
break;
default:
cout << "\nINVALID CHOICE..." << endl;
}
}
return 0;
}