andersch.dev

<2024-10-26 Sat>

Stack

A stack is a data structure that follows the last-in, first-out (LIFO) principle, where elements are pushed onto and popped off from the top of the stack.

API

typedef struct stack_t {
    int top;
    #define MAX_STACK_SIZE 100
    int items[MAX];
} stack_t;

void stack_push(stack_t* stack, int item); // add new top element
int  stack_pop(stack_t* stack);            // remove top element
int  stack_peek(stack_t* stack);           // peek top without popping