-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSTL_stack_queue.cpp
More file actions
145 lines (129 loc) · 2.18 KB
/
Copy pathSTL_stack_queue.cpp
File metadata and controls
145 lines (129 loc) · 2.18 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//Write C++ program using STL for implementation of stack & queue using SLL
#include<iostream>
#include<iterator>
#include<list>
using namespace std;
class stack
{
list <int> lst;
public:
list<int>::iterator st,en;
void push1(int a);
void pop1();
void display();
};
void stack::push1(int a)
{
lst.push_back(a);
}
void stack::pop1()
{
lst.pop_back();
}
void stack::display()
{
st=lst.begin();
en=lst.end();
cout<<"\n~~~STACK~~~\n";
while(st!=en)
{
en--;
cout<<*en<<"\n";
}
}
class queue{
list <int> lst;
public:
list<int>::iterator st,en;
void push1(int);
void pop1();
void display();
};
void queue::push1(int a){
lst.push_back(a);
}
void queue::pop1(){
lst.pop_front();
}
void queue::display(){
st=lst.begin();
en=lst.end();
cout<<"\n~~~QUEUE~~~\n";
while(st!=en)
{
en--;
cout<<*en<<"\n";
}
}
int main()
{
stack s;
queue q;
int a,ch,soq;
char choice;
do{
cout<<"\n1)Queue\n2)Stack\n3)Exit Program\n";
cin>>ch;
switch(ch)
{
case 1:
do{
cout<<"\n=======!!!!!!!!!..........QUEUE..........!!!!!!!!!=======\n";
cout<<"\n1)Push to queue\n2)Pop from queue\n3)Display my queue\n4)Return to Main Menu\n";
cin>>soq;
switch(soq){
case 1:
cout<<"Enter Integer :";cin>>a;
q.push1(a);
cout<<"\n\n!!..Pushed..!!\n\n";
choice='y';
break;
case 2:
q.pop1();
cout<<"\n\n!!..Popped..!!\n\n...New Queue is...\n";
q.display();
choice='y';
break;
case 3:
q.display();
choice='y';
break;
case 4:
cout<<"Continue to Queue? y/n : ";cin>>choice;
break;
}
}while(choice=='y');
break;
case 2:
do{
cout<<"\n=======!!!!!!!!!..........STACK..........!!!!!!!!!=======\n";
cout<<"\n1)Push to Stack\n2)Pop from Stack\n3)Display my Stack\n4)Return to Main Menu\n";
cin>>soq;
switch(soq){
case 1:
cout<<"Enter Integer :";cin>>a;
s.push1(a);
cout<<"\n\n!!..Pushed..!!\n\n";
choice='y';
break;
case 2:
s.pop1();
cout<<"\n\n!!..Poped..!!\n\n...New Stack is...\n";
s.display();
choice='y';
break;
case 3:
s.display();
choice='y';
break;
case 4:
cout<<"Continue to Stack? y/n : ";cin>>choice;
break;
}
}while(choice=='y');
break;
case 3:
return 0;
}
}while(1);
}