Data Structures · Stack ADT

A stack built from a linked list

Push and pop values and watch the C++ run one line at a time. Each value lives in its own Node on the heap. head points to the top of the stack, and tail points to the bottom node, whose next is nullptr.

Heap: the nodes, from head to tail

Variables

What is happening

ReadyType a number and press push(x).

Calls from main()

    LinkedStack.cpp

      Unlike the array version, this stack never fills up: each push asks the heap for a new node. That is also why pop() must delete the old node, or the memory leaks.