Data Structures · Stack ADT

A stack stored in an array

Push and pop values and watch the C++ run one line at a time. The stack lives in a fixed array of 8 ints. topIndex marks the top (the head), and data[0] is always the bottom (the tail).

Memory: int data[8]

topIndex
bottom
On the stack Old value still in memory, no longer on the stack Never written

Variables

What is happening

ReadyType a number and press push(x), or try pop() on the stack below.

Calls from main()

    ArrayStack.cpp

      Notice that pop() only moves topIndex down. The old value stays in the array until a later push writes over it.