-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.c
More file actions
54 lines (54 loc) · 1.27 KB
/
stack.c
File metadata and controls
54 lines (54 loc) · 1.27 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
#include <stdio.h>
#define Max_Size 10
int stack[Max_Size];
int top=-1;
void push(int item){
if(top==Max_Size-1)
printf("Stack Overflow\n");
else
stack[++top]=item;
}
void pop(){
if(top<0)
printf("Stack underflow\n");
else
printf("%d is delete\n",stack[--top]);
}
void viewStack(){
int i;
printf("stack is\n");
if(top<0)
printf("Stack empty\n");
else{
printf("\nStack\n");
for(i=0;i<=top;i++){
printf("%d\n",stack[i]);
}
}
}
void main(){
int n,item;
char dis;
printf("\tStack Menu\n");
printf("1 - Push \n2 - pop\n4 - Satck View\n3 - Exit\n");
do{
printf("\nEnter \t");
scanf("%d",&n);
switch(n){
case 1:printf("Enter element\t");
scanf("%d",&item);
push(item);
viewStack();
break;
case 2:pop(item);
viewStack();
break;
case 3:viewStack();
break;
case 4:break;
default:printf("Wrong input\n");
printf("\tStack Menu\n");
printf("1 - Push \n2 - pop\n4 - Satck View\n3 - Exit\n");
}
}while(n!=3);
}