#include "stack.h" #include #define STACK_SIZE 100 struct stack_st stack = { .len = 0, .arr = {0}}; // Functions void stackPush(int val){ if (stack.len >= STACK_SIZE){ printf("Stack overrflow\n"); return; } stack.arr[stack.len] = val; stack.len++; return; } int stackPop(void){ if (stackIsEmpty()){ return 0; } int stackPopped = stack.arr[--stack.len]; return stackPopped; } int stackIsEmpty(void) { return !(stack.len > 0); } int stackPeek(){ // To avoid funking up the stack.len if (stackIsEmpty()) return 0; else if (stack.len == 1) return stack.arr[1]; else{ int x = stackPop(); stackPush(x); return x; } } void stackPrint(){ while(1){ if(stackIsEmpty()) break; int x = stackPop(); printf("%d\n", x); } return; }