-
Notifications
You must be signed in to change notification settings - Fork 243
/
stack.c
56 lines (47 loc) · 800 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
#include <stdio.h>
#define MAX 5
int stack[MAX];
int top = -1;
void push(){
int x;
if(top == MAX - 1){
printf("Overflow\n");
}
else{
printf("Enter Data : ");
sacnf("%d", &x);
top ++;
stack[top] = x;
}
}
void pop(){
if(top == -1){
printf("Stack is Empty\n");
}
else{
printf("Popped Element : %d\n", stack[top]);
top--;
}
}
void display(){
if(top == -1){
printf("Stackis Empty\n");
}
else{
printf("The Stack is : ");
for(int i = top; i >= 0; i --){
printf("%d\t", stack[i]);
}
}
}
void peek(){
if(top == -1){
printf("Stackis Empty\n");
}
else{
printf("%d", stack[top]);
}
}
int main(){
return 0;
}