C/C++ Arena

Step 6 of 6

A stack on an array

A stack is last-in, first-out, like a pile of plates: push adds on top, pop removes from the top.

typedef struct {
    int items[64];
    int top;        // number of items
} Stack;

Your turn: implement push (return 0 if full, 1 if ok) and pop (return the top item and remove it; the caller guarantees the stack isn't empty).

Previous: Reverse a linked list