-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patha08.cpp
More file actions
106 lines (105 loc) · 2.43 KB
/
a08.cpp
File metadata and controls
106 lines (105 loc) · 2.43 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
//============================================================================
// Name : Assignment.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <bits/stdc++.h>
using namespace std;
void menuStack(){
cout<<"\n Press 1: Push Element into Stack";
cout<<"\n Press 2: Pop Element from Stack";
cout<<"\n Press 3: Find Stack Size";
cout<<"\n Press 4: Display Stack Elements";
cout<<"\n Press 5: Display Top";
cout<<"\n Press 6: Show Menu";
cout<<"\n Press 0: Exit Program";
}
void menuQ(){
cout<<"\n Press 1: Push Element into Queue";
cout<<"\n Press 2: Pop Element from Queue";
cout<<"\n Press 3: Find Queue Size";
cout<<"\n Press 4: Display Queue";
cout<<"\n Press 5: Display Front";
cout<<"\n Press 6: Show Menu";
cout<<"\n Press 0: Exit Program";
}
void displayStack(stack <int> a){
cout<<"\nStack: ";
while(!a.empty()){
cout<<"\n"<<a.top();
a.pop();
}
}
void displayQ(queue <int> a){
cout<<"\n Queue: ";
while (!a.empty()){
cout<<a.front()<<" ";
a.pop();
}
}
void _stack(){
stack <int> a;
menuStack();
int ch,element;
do{
cout<<"\n------------------------------------";
cout<<"\n Enter Choice From Menu [0-Exit]: ";
cin>>ch;
switch(ch){
case 1: cout<<"\n Enter Element: ";cin>>element;
a.push(element);
break;
case 2: a.pop();
break;
case 3: cout<<"Size: "<<a.size();
break;
case 4: displayStack(a);
break;
case 5: cout<<"\n Top: "<<a.top();
break;
case 6: menuStack();
break;
case 0: break;
default: cout<<"\n Wrong Choice!";
}
}while(ch);
}
void _que(){
queue <int> a;
menuQ();
int ch,element;
do{
cout<<"\n------------------------------------";
cout<<"\n Enter Choice From Menu [0-Exit]: ";
cin>>ch;
switch(ch){
case 1: cout<<"\n Enter Element: ";cin>>element;
a.push(element);
break;
case 2: a.pop();
break;
case 3: cout<<"Size: "<<a.size();
break;
case 4: displayQ(a);
break;
case 5: cout<<"\n Front: "<<a.front();
break;
case 6: menuQ();
break;
case 0: break;
default: cout<<"\n Wrong Choice!";
}
}while(ch);
}
int main() {
int ch;
cout<<"\n Press: 1 for Stack";
cout<<"\n Press: 2 for Queue";
cout<<"\n Enter Choice: ";cin>>ch;
if(ch==1)_stack();
else if(ch==2)_que();
cout<<"Terminated!";
return 0;
}