-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.c
More file actions
61 lines (48 loc) · 976 Bytes
/
stack.c
File metadata and controls
61 lines (48 loc) · 976 Bytes
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
#include<stdio.h>
#define max 20
int arr[max];
int top = -1;
void Push(){
top++;
if(top==max-1){
printf("Stack is Full!\n");
}
else{
printf("Enter element: ");
scanf("%d",&arr[top]);
}
}
void Pop(){
if(top==-1){
printf("Stack is empty\n");
}
else{
printf("Removed item is %d\n",arr[top]);
top--;
}
}
void Display(){
if(top==-1){
printf("Stack is empty\n");
}
else{
for(int i=0;i<=top;i++){
printf("%d ",arr[i]);
}
printf("\n");
}
}
int main(){
printf("1.Push\n2.Pop\n3.Display\n4.Exit\n");
while(1){
int o;
printf("Enter option :");
scanf("%d",&o);
switch(o){
case 1:Push();break;
case 2:Pop();break;
case 3:Display();break;
case 4:return 0;
}
}
}