Skip to main content
Twisuki+3
Word count: 382
Est. read time: 2 min
Last edited: 2026-07-17
Graduate Texts in Minecraft
Graduate Texts in Minecraft

A. Stacks

This chapter introduces stacks and call stacks, which will help you understand block updates.

A stack is a first-in-last-out (FILO) data structure, where elements can only be added or removed at one end.

Imagine a Pringles can:

  • Chips can only be placed in from the top, and can only be taken out from the top.
  • Therefore, the chip placed at the bottom first will be the last one that can be taken out.

This is the "first in last out" principle.

A stack is like a Pringles can.
In data structure terminology:

  • "Putting chips into the can" corresponds to push;
  • "Taking chips from the top" corresponds to pop.

Additionally:

  • The top of the can is equivalent to the top of the stack
  • The bottom of the can is equivalent to the bottom of the stack

That's a stack.

A call stack is a mechanism that programs use at runtime to manage function calls. It relies on the first-in-last-out rule to ensure functions return correctly.

Imagine you're making phone calls to ask a question:

  1. You call your friend A to ask a question.
  2. A doesn't know the answer, so they call their friend B to ask.
  3. B isn't sure either, so they call their friend C to ask.

This time, C finds the answer and tells B first.
B then tells A.
Finally, A tells you the answer.

This follows the call stack pattern:

  • Each phone call pushes a new "call task" onto the "call stack".
  • When C is searching for the answer, the task at the top of the stack is "C searching for the answer".
  • After C finds the answer, the most recent call completes first, then returns layer by layer to the callers (B → A → you).
  • Your initial phone call was the first task pushed onto the call stack, so it sits at the bottom of the stack.

In a program:

  • "Making a phone call" is equivalent to calling a function;
  • "Getting an answer and passing it back" is equivalent to a function returning a result.

This way, when functions are nested, the program can ensure each function completes and returns to its caller correctly.