-
Notifications
You must be signed in to change notification settings - Fork 0
/
queuethroughlinkedlist.cpp
88 lines (81 loc) · 1.86 KB
/
queuethroughlinkedlist.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
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
#include<iostream>
using namespace std;
struct node {
int info;
node* next;
};
node* f = nullptr;
node* e = nullptr;
void insert(int value) {
node* nn = new node;
nn->info = value;
nn->next = nullptr;
if (e == nullptr) {
e = f = nn;
}
else {
while (e->next != nullptr) {
e = e->next;
}
e->next = nn;
}
}
void del() {
if (f == nullptr) {
cout << "Queue empty" << endl;
return;
}
node* temp = f;
f = f->next;
delete temp;
}
void display() {
node* temp1 = f;
cout << "Front";
if (f == nullptr) {
cout << "Queue empty";
}
else {
while (temp1 != nullptr) {
cout << temp1->info << "->";
temp1 = temp1->next;
}
cout << "END";
cout << "start value" << f->info << endl;
}
}
int main() {
int x, choice;
char ch;
do {
cout << "QUEUE" << endl;
cout << "1. INSERTION" << endl;
cout << "2. DELETION" << endl;
cout << "3. EXIT" << endl;
cout << "Enter your choice:" << endl;
cin >> choice;
switch (choice) {
case 1:
do {
cout << "Enter value: ";
cin >> x;
insert(x);
cout << "Do you want to insert more? (Y/N): ";
cin >> ch;
} while (toupper(ch) == 'Y');
display();
break;
case 2:
del();
display();
break;
case 3:
exit(0);
break;
default:
cout << "Wrong choice" << endl;
break;
}
} while (true);
return 0;
}