Bugsy
Explains
3 hearts left

Stacks and queues

New idea

Why does Undo remove the last thing you did?

Type "a", then "b", then "c", and press Undo. You lose the "c", not the "a". The newest action is the first one undone.

A pile where the last item in is the first item out is called a stack, like plates in a cupboard. You add to the top and take from the top.

In code, adding to a stack is push(stack, x) and taking the top item off is pop(stack). pop also gives you back the item it removed.

A stack is usually kept in an array. An array handed to a function is the same array, not a copy (unlike the numbers in b = a), so push and pop really change it.