-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSTACK menu driven.c
69 lines (65 loc) · 1.18 KB
/
STACK menu driven.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
#include<stdio.h>
void push(int A[],int *Top,int Size)
{
if(*Top==Size-1)
printf("overflow\n");
else
{
(*Top)++;
printf("Enter the elements: \n");
scanf("%d",&A[*Top]);
}
}
void pop(int A[],int *Top)
{
if(*Top==-1)
printf("overflow\n");
else
{
printf("Deleted Elements is %d: \n",A[*Top]);
(*Top)--;
}
}
void display(int A[],int Top)
{
if(Top==-1)
{
printf("underflow\n");
}
else
{
for(int i=Top; i>=0; i--)
{
printf("%d",A[i]);
}
}
}
void main()
{
do {
int A[10],Top, Size, choice;
Top-1;
printf("\nEnter the Size of STACK: \n");
scanf("%d",&Size);
printf("Main Menu\n");
printf("1.Push\n");
printf("2.Pop\n");
printf("3.Display\n");
printf("0.Exit\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
push(A,&Top,Size);
break;
case 2:
pop(A,&Top);
break;
case 3:
display(A,Top);
break;
case 0:
exit(0);
}
} while(1);
}