-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue
More file actions
85 lines (71 loc) · 1.41 KB
/
Copy pathQueue
File metadata and controls
85 lines (71 loc) · 1.41 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
Write C++ program using STL for implementation of stack & queue using SLL
*/
#include<iostream>
#include<string.h>
#include<list>
using namespace std;
class Queue
{
public :
int a;
list <int> s;
list <int> :: iterator itr;
void push()
{
cout<<"\n Enter a number : ";
cin>>a;
s.push_back(a);
}
void displaystack()
{
cout<<"\n The elements in the queue are : "<<"\n";
for(itr=s.begin() ; itr!=s.end() ; itr++)
{
cout<<*itr<<"\t";
}
}
void pop()
{
itr=s.begin();
s.pop_front();
cout<<"\n The element popped out of the queue is "<<*itr;
}
};
int main()
{
Queue p;
int choice;
char ans;
do
{
cout<<"\n 1. Add element \n 2. Delete element \n 3. Display queue elements";
cout<<"\n Enter the operation you want to perform : ";
cin>>choice;
switch(choice)
{
case 1 : p.push();
break;
case 2 : p.pop();
break;
case 3 : p.displaystack();
break;
}
cout<<"\n Do you want to perform any other operation ?";
cin>>ans;
}while(ans=='Y' || ans=='y');
}
/*
OUTPUT:-
1. Add element
2. Delete element
3. Display queue elements
Enter the operation you want to perform : 1
Enter a number : 2
Do you want to perform any other operation ?y
1. Add element
2. Delete element
3. Display queue elements
Enter the operation you want to perform : 2
The element popped out of the queue is 2
Do you want to perform any other operation ?n
*/