Stack: Size
Task: Count how many values the stack holds
What you are watching
A stack does not count its values when asked how many it has. It keeps the top pointer up to date on every push and pop, so size is that number plus one - read, never walked. Three pushes take it to three and one pop takes it back to two, and the answer costs the same whether the stack holds three values or three million.