-
Notifications
You must be signed in to change notification settings - Fork 2
/
stack.c
52 lines (50 loc) · 1.25 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
#include<stdio.h>
#include<stdlib.h>
int stack[5], top;
void Push(int);
int Pop();
void main(){
int choice, item, i;
top = -1;
while(1)
{
printf("1. Push \n2.Pop\n3.Display\n4.Exit\nEnter your Choice: ");
scanf("%d", &choice);
switch(choice){
case 1: if(top == 4) printf("OverFlow Error\n");
else{
printf("Enter the element you want to push\n");
scanf("%d", &item);
Push(item);
}
break;
case 2: if(top == -1){
printf("Underflow Error\n");
}else{
item = Pop();
printf("Deleted Element is= %d\n", item);
}
break;
case 3: if(top == -1)
printf("Stack is Empty");
else{
for(int i = 0; i<= top; i++){
printf("%d\t", stack[i]);
}
printf("\n");
}
break;
case 4: exit(0);
}
}
}
void Push(int item){
top++;
stack[top] = item;
}
int Pop(){
int t;
t = stack[top];
top--;
return t;
}