Section 21.5 Stacks
• A stack is a last-in, first-out (LIFO) data structure (p. 886). The primary methods used to manipulate a stack are push (p. 887) and pop (p. 887), which add a new node to the stack’s top and remove a node from the top, respectively. Method pop returns the removed node’s data.
• When a method call is made, the called method must know how to return to its caller, so the return address is pushed onto the program-execution stack. If a series of method calls occurs, the successive return values are pushed onto the stack in last-in, first-out order.
• The program-execution stack contains the space created for local variables on each invocation of a method. When the method returns to its caller, the space for that method’s local ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access