-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstack.c
60 lines (54 loc) · 923 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
#include <stdio.h>
int top = -1;
int stack[100];
void push(int element){
if(top == 100){
printf("Stack is full\n");
return;
}
top++;
stack[top] = element;
printf("Element added\n");
}
void pop(){
if(top == -1){
printf("Stack is empty\n");
return;
}
top --;
printf("Element poped\n");
}
void display(){
if(top == -1){
printf("Stack is empty\n");
return;
}
for(int i=0; i<=top; i++){
printf("%d\t", stack[i]);
}
printf("\n");
}
void main(){
int option, flag=1;
while(flag==1){
printf("\nEnter the number associated to an operation\n1. Push\n2. Pop\n3. Display\nEnter any other number to exit\n>>");
scanf("%d", &option);
switch(option){
case 1:
int element;
printf("Enter the element to push: ");
scanf("%d", &element);
push(element);
break;
case 2:
pop();
break;
case 3:
display();
break;
default:
flag = 0;
break;
}
}
}