-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathStack.c
64 lines (63 loc) · 1.59 KB
/
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
#include<stdio.h>
#include<stdlib.h>
#define MAX 50
int main()
{
int stack[MAX],choice,item,Top=-1,i;
while (i)
{
printf("\n****MENU ****\n");
printf("\n****Push");
printf("\n****2.Pop");
printf("\n****3.Display");
printf("\n****4.Exit");
printf("\n Enter your choice");
scanf("%d",&choice);
switch (choice)
{
case 1:
{
if (top == MAX-1)
printf("Stack overfow");
else
{
printf("\n Enter the value to be entered");
scanf("%d",&item);
Top++;
stack[top] = item;
}
break;
}
case 2:
{
if (top ==-1)
printf("Stack is empty");
else
{
printf("Popped element is %d",stack[top]);
Top--;
}
break;
}
case 3:
{
if (top ==-1)
printf("Stack is empty");
else
{
printf("\n Displaying stack");
for ( i = Top; i >= 0; i++)
{
printf("%d",stack[i]);
}
}
break;
}
case 4:
{
exit(0)
}
}
}
return 0;
}