-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patharray implementation of stack.cpp
More file actions
92 lines (83 loc) · 2.12 KB
/
array implementation of stack.cpp
File metadata and controls
92 lines (83 loc) · 2.12 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
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
//adding headers
#include <iostream>
#define max 100
int a[max];
int top=-1,n,m;
using namespace std;
void push(int data)
{
if (top==max-1)
{
cout<<"stack overflow";
return;
}
top++;
a[top]=data;
}
void pop() //poping iut element
{
if(top==-1)
{
cout<<"stack underflow";
return;
}
top--;
}
void print(int T)
{
cout<<"Your stack is:\n";
while(T>=0)
{
cout<<a[T]<<endl;
T--;
}
}
void choice()
{ while(1)
{
int ch,d;
cout<<"ENTER YOUR CHOICE FROM BELOW:-"<<endl;
cout<<"1.push element in stack:\n";
cout<<"2.pop element from the stack\n";
cout<<"3.print stack element\n";
cout<<"4.to Exit"<<endl;
cin>>ch;
switch(ch)
{
case 1: cout<<"how many elements you want to enter in stack:";
cin>>n;
for(int i=1;i<=n;i++)
{
cout<<"enter "<<i<<"st element:";
cin>>d;
push(d);
cout<<"Pushed in stack"<<endl;
}
break;
case 2: cout<<"how many element you want to pop:";
cin>>m;
for(int j=1;j<=m;j++)
{
pop();
cout<<"poped "<<j<<" times "<<endl;
}
break;
case 3: print(top);
break;
case 4: exit(1);
default:
cout<<"Invalid choice!"<<endl;
break;
} cout<<endl;
}
}
int main()
{
choice();
return 0;
}