-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.c
More file actions
63 lines (62 loc) · 1.01 KB
/
stack.c
File metadata and controls
63 lines (62 loc) · 1.01 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
#include<stdio.h>
#include<stdlib.h>
#define max 1
int top=-1;
int stack[max];
void push(int x)
{
if(top==max)
printf("Stack overflow\n");
else
{
stack[++top]=x;
printf("Element pushed into stack\n");
}
}
void pop()
{
if(top==-1)
printf("stack underflow\n");
else
{
printf("Element popped out %d\n",stack[top]);
top--;
}
}
void main()
{
int ch;
while(1)
{
printf("1.push\n2.pop\n3.display\n4.exit\n");
scanf("%d",&ch);
switch(ch)
{
case 1: {printf("\nEnter Element\n");
int x;
scanf("%d",&x);
push(x);
break;
}
case 2:
{
pop();
break;
}
case 3:
{
int i;
for(i=0;i<=top;i++)
printf("%d ",stack[i]);
printf("\n");
break;
}
case 4:
{
exit(-1);
break;
}
}
}
getch();
}