-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathStack.c
67 lines (65 loc) · 885 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
#include <stdio.h>
#define SIZE 2
int top = -1, stack[SIZE];
void push(int x)
{
if (top == SIZE - 1)
printf("Stack overflow\n");
else stack[++top] = x;
}
void pop()
{
if (top == -1) printf("Stack underflow\n");
else
{
printf("%d\n", stack[top]);
top--;
}
}
void display()
{
int i;
printf("Content of the stack\n");
for (i = 0; i <= top; i++)
printf("%d\t", stack[i]);
printf("\n");
}
void main()
{
int x, option;
char c;
do
{
printf("Which operation is to be done?\n1 : push\n2 : pop\n3 : Display elements\n Enter option :");
scanf("%d", &option);
switch (option)
{
case 1:
{
printf("Enter element to push :");
scanf("%d", &x);
push(x);
break;
}
case 2:
{
pop();
break;
}
case 3:
{
display();
break;
}
default:
{
printf("Wrong Input\n");
}
}
getchar();
printf("Do you want to continue?(y/n) :");
scanf("%c", &c);
}
while (c == 'y' || c == 'Y');
printf("\n");
}