-
Notifications
You must be signed in to change notification settings - Fork 1
/
STACK.c
71 lines (67 loc) · 804 Bytes
/
STACK.c
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
#include<stdio.h>
#define pf printf
#define sf scanf
#define size 3
int stack[size];
int top;
void push ();
void pop ();
void display ();
void main ()
{
top = -1;
int ch;
do
{
pf("\n1:push\n2:pop\n3:display\n4:exit\nchoice:");
sf("%d",&ch);
switch(ch)
{
case 1: push();break;
case 2: pop();break;
case 3: display();break;
case 4: pf("Program End");break;
default: pf("Does Not Exit");break;
}
}while(ch!=4);
}
void push ()
{
int x;
if(top==size-1)
{
pf("stack is full");
return;
}
pf("enter data");
sf("%d",&x);
top++;
stack[top]=x;
pf("%d is pushed",x);
}
void pop ()
{
int x;
if(top==-1)
{
pf("stack is empty");
return ;
}
x=stack[top];
stack[top]=0;
top--;
pf("%d is poped",x);
}
void display()
{
int i;
if(top==-1)
{
pf("stack is empty");
return;
}
for(i=top;i>=0;i--)
{
pf("%d\n",stack[i]);
}
}