forked from ajinkya48765/Academic_Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack_queue_using_STL.cpp
More file actions
163 lines (146 loc) · 2.75 KB
/
Copy pathstack_queue_using_STL.cpp
File metadata and controls
163 lines (146 loc) · 2.75 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
//Program to implement stack and queue using SSL
#include <algorithm>
#include <stack>
#include <queue>
#include <iostream>
#include <iterator>
#include <string>
using namespace std;
int showstack(stack <int>);
class stk
{
};
int displayqueue( queue <int>);
int displaystack( stack <int>);
int main()
{
char choice;
int n;
stack <int>s;
queue <int>q;
while(1)
{
cout<<"\n\n*** PROGRAM FOR IMPLEMENTATION OF STACK AND QUEUE USING STL ***"<<endl;
cout<<"(1) Stack Operations \n(2) Queue Operations"<<endl;
cout<<"Enter your choice"<<endl;
cin>>choice;
if(choice=='1')
{
while(1)
{
cout<<"\nYou are in stack\n";
cout<<"(1) push \n(2) pop \n(3) size \n(4) display \n(5) top \n(6) exit "<<endl;
cout<<"Enter your choice"<<endl;
cin>>choice;
switch(choice)
{
case '1':
cout<<"\nenter the number to push\n";
cin>>n;
s.push(n);
break;
case '2':
if(s.empty()==1)
{
cout<<"\nstack is empty\n";
break;
}
else
{
s.pop();
cout<<"\nelement popped successfully\n";
break;
}
case '3':
cout<<"\nSize of stack is "<<s.size()<<endl;
break;
case '4':
displaystack(s);
break;
case '5':
cout<<"\nTop of stack is "<<s.top()<<endl;
break;
default:
cout<<"\nout of the stack now....\n\n";
goto exit;
break;
}
}
}
else if(choice=='2')
{
while(1)
{
cout<<"\nYou are in queue\n";
cout<<"(1) add \n(2) remove \n(3) size \n(4) display \n(5) front \n(6) end \n(7) exit "<<endl;
cout<<"Enter your choice"<<endl;
cin>>choice;
switch(choice)
{
case '1':
cout<<"\nenter the number to add\n";
cin>>n;
q.push(n);
break;
case '2':
if(q.empty()==1)
{
cout<<"\nqueue is empty\n";
break;
}
else
{
q.pop();
cout<<"\nelement removed successfully\n";
break;
}
case '3':
cout<<"\nSize of queue is "<<q.size()<<endl;
break;
case '4':
displayqueue(q);
break;
case '5':
cout<<"\nFront of queue is "<<q.front()<<endl;
break;
case '6':
cout<<"\nEnd of queue is "<<q.back()<<endl;
break;
default:
cout<<"\nout of the queue now....\n\n";
goto exit;
break;
}
}
}
else
{
cout<<"\nwrong choice\n";
}
exit:
cout<<"\n Do you want to continue(Y/N)\n";
cin>>choice;
if(choice=='y')
choice='Y';
if (choice!='Y')
break;
}
}
int displaystack(stack <int>s)
{
while(!s.empty())
{
cout<<" "<<s.top()<<endl;
s.pop();
}
return 0;
}
int displayqueue(queue <int>q)
{
while(!q.empty())
{
cout<<" "<<q.front()<<endl;
q.pop();
}
return 0;
}