-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsllStack.cpp
More file actions
64 lines (58 loc) · 1.58 KB
/
sllStack.cpp
File metadata and controls
64 lines (58 loc) · 1.58 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
/*
Author @ Pradeep Kumar
Objective : To Create Stack Using STL Link List
Function :-
main()
-> Creating Stack Using STL Link List
Parameter ->
choice ->character type variable use for switching
choice1 ->character type variable use for whether user continue the programe or exit
l -> list type variable
Result: we get a Stack from a link list
*/
// Approach : Take a Stl list and use a inbuilt function list.push_back(element) to push a value into stack and use list.pop_back() to pop a stack
#include<iostream>
#include<list>
#include<conio.h>
using namespace std;
int main()
{
list <int> l;
list <int> temp;
int choice,element;
char choice1;
cout<<"1) Push A Value Into Stack"<<endl;
cout<<"2) Pop A Value From Stack"<<endl;
cout<<"3) Print A Value Of Stack"<<endl;
do
{
cout<<"Enter Your Choice"<<endl;
cin>>choice;
switch(choice)
{
case 1:
cout<<"Enter Value to be pushed into stack"<<endl;
cin>>element;
l.push_back(element) ;
break;
case 2:
if(l.empty())
{
cout<<"stack is empty !"<<endl;
}
else
{
l.pop_back();
}
break;
case 3:
for (list<int>::iterator i = l.begin(); i != l.end(); ++i)
cout << *i <<" ";
break;
default :
cout<<"please enter right option !"<<endl;
}
cout<<" Press y for continue......"<<endl;
cin>>choice1;
}while(choice1 == 'y'||choice1 == 'Y');
}