-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.c
More file actions
39 lines (39 loc) · 796 Bytes
/
stack.c
File metadata and controls
39 lines (39 loc) · 796 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
#include<stdio.h>
int max;
int stack[10000];
int top=-1;
void stack_push(){
if(top==max-1) printf("stack overflow!\n");
else {
int x;
scanf("%d",&x);
top++;
stack[top]=x;
}
}
void stack_pop(){
if(top==-1) printf("stack in empty!\n");
else{
top--;
}
}
void stack_top(){
if(top==-1) printf("stack is empty!\n");
else {
printf("%d \n",stack[top]);
}
}
void stack_display(){
if(top==-1) printf("stack in empty!\n");
else {
for(int i=0; i<=top; i++) printf("%d ",stack[i]);
}
}
int main(){
printf("Enter number of element in stack:");
scanf("%d",&max);
for(int i=0; i<max; i++) stack_push();
stack_top();
stack_pop();
stack_top();
}