It's made out of my own mind, not from the book, but from my own perspective, so why hasn't it been implemented according to the scenario?
Stack omitted empty and full due to code length
#include<stdio.h>
typedef struct stack{
int key[100];
int top;
}stack;
void init(stack* a){
int i;
for(i=0;i<100;i++){
a->key[i]=0;
}
a->top = 0;
}
void push(stack* a, int num){
a->key[a->top++] = num;
}
int pop(stack* a){
return a->key[a->top--];
}
int main(void){
stack a;
init(&a);
push(&a,10); push(&a,20); push(&a,30);
printf("%d ",pop(&a)); printf("%d ",pop(&a)); printf("%d ",pop(&a));
return 0;
}
I expect the output 30 20 10 but the actual output is 0 30 20