-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.cpp
More file actions
95 lines (65 loc) · 1.41 KB
/
stack.cpp
File metadata and controls
95 lines (65 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
86
87
88
89
90
91
92
93
94
95
#include<iostream>
using namespace std;
int top=-1;
int size;
int push(int val,int st[])
{
if(top==size-1)
{
cout<<"--Stack Overflow---";
return 0;
}
else
{
top=top+1;
st[top]=val;
}
}
int pop(int st[])
{
if(top==-1)
{
cout<<"\n---Stack Underflow---";
return 0;
}
else
{
cout<<"\nElement Poped Out of stack is --"<<st[top];
top=top-1;
}
}
int main()
{
int ch;
int st[size];
cout<<"\nEnter the size of the Stack";
cin>>size;
do{
cout<<"\n----Stack Operations---";
cout<<"\n1.Push";
cout<<"\n2.Pop";
cout<<"\n3.Exit";
cout<<"\nEnter yourr choice--";
cin>>ch;
switch(ch)
{
case 1:
int n,val;
cout<<"\nEnter the no of values you want to push into the stack";
cin>>n;
for(int i=0;i<n;i++)
{
cin>>val;
push(val,st);
}
cout<<"\nElements pushed successfully----";
break;
case 2:
pop(st);
break;
case 3:
break;
}
}while(ch!=3);
return 0;
}