-
Notifications
You must be signed in to change notification settings - Fork 3
/
stack.c
59 lines (52 loc) · 940 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
#include <stdio.h>
int n = 7;
int stack[10];
int top = -1;
void push(int x){
if(top==n){
printf("\n Stak is overflow!");
}
else{
top++;
stack[top] = x;
}
}
void pop(){
if(top==-1){
printf("\n Stack is underflow");
}else{
printf("\n Element to be delete:%d", stack[top]);
top--;
}
}
void distroy(){
top= -1;
printf("\n Stack is destroyed!");
}
void display(){
if(top==-1){
printf("\n Stack is underflow");
}else{
printf("\n stack elements:");
for(int i=0; i<=top; i++){
printf("%d ", stack[i]);
}
}
}
void main(void) {
display();
push(1);
push(2);
push(3);
push(4);
display();
pop();
display();
distroy();
}
// ===== OUTPUT =====
// Stack is underflow
// stack elements:1 2 3 4
// Element to be delete:4
// stack elements:1 2 3
// Stack is destroyed!