forked from grantslone/HacktoberFest-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack(Array).cpp
More file actions
47 lines (40 loc) · 910 Bytes
/
Stack(Array).cpp
File metadata and controls
47 lines (40 loc) · 910 Bytes
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
#include<iostream>
int main(){
int a[50];
int c=0;
int top=-1,data;
while(c<3){
cout<<"1.Push\n2.Pop\n3.Exit\n";
cin>>c;
switch(c){
case 1:
top++;
if(top>49){
top--;
cout<<"Overflow\n";
}
else{
cout<<"Enter Data\n";
cin>>a[top];
cout<<"Item Inserted\n";
}
break;
case 2:
if(top==-1){
cout<<"Underflow\n";
}
else{
top--;
}
break;
}
if(top!=-1){
cout<<"Stack:\n";
for(int i=top;i>=0;i--){
cout<<"<-"<<a[i];
}
cout<<"\n";
}
}
return 0;
}