-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathpush in stack using array.cpp
More file actions
63 lines (62 loc) · 942 Bytes
/
Copy pathpush in stack using array.cpp
File metadata and controls
63 lines (62 loc) · 942 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>
#include<string.h>
using namespace std;
class stack
{
public:
int size,top,*s;
};
void createstack(stack *st)
{
cout<<"Enter Size of the stack : ";
cin>>st->size;
st->s=new int[st->size];
st->top=-1;
}
void push(stack *st,int val)
{
if(st->top==st->size-1)
{
cout<<"OVERFLOW";
}
else
{
st->top++;
st->s[st->top]=val;
}
}
void printstack(stack st)
{
for(int i=st.top;i>=0;i--)
{
cout<<st.s[i]<<endl;
}
}
int main()
{ char n[3];
stack st;
int i=1,l,u;
createstack(&st);
cout<<"Enter first element in the stack : ";
cin>>u;
push(&st,u);
while(i<=st.size-1)
{
cout<<"DO YOU WANT TO PUSH AN ELEMENT IN THE STACK?\nYES OR NO\nCHOICE =";
cin>>n;
if(strcmp(n,"yes")==0||strcmp(n,"Yes")==0)
{
cout<<"Enter value for the next node:";
cin>>l;
push(&st,l);
}
else
{
cout<<"Dhanyawaad aapka\n";
break;
}
i++;
}
printstack(st);
return 0;
}