forked from anoop-singh-dev/data-structures
-
Notifications
You must be signed in to change notification settings - Fork 0
/
array_stack.c
52 lines (50 loc) · 960 Bytes
/
array_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
#include <stdio.h>
#define MAX 10
#include <stdlib.h>
int top = -1;
void push(int stack[],int value){
if(top < MAX){
top = top + 1;
stack[top] = value;
}
else{
printf("the stack is full can not push\n");
exit(0);
}
}
void display(int stack[]){
int i =0;
printf("current stack is..\n");
for(i=0;i<=top;i++){
printf("%d\n",stack[i]);
}
}
void pop(int stack[],int *value){
if(top >= 0){
*value = stack[top];
top = top - 1;
}
else{
printf("the stack is empty\n");
exit(0);
}
}
int main(){
int stack[MAX];
int value; char c;
do{
printf("enter a for push, b for pop, n for exit\n");
scanf("%c",&c);
switch(c){
case 'a': printf("enter element for appending\n");
scanf("%d",&value);
push(stack,value);
break;
case 'b': pop(stack,&value);
printf("the value poped is %d\n",value);
break;
}
}while(((c!='a')||(c!='b'))&&(c!='n'));
display(stack);
return 0;
}