liveBook · Manning

First-in-last-out structure

Also called LIFO, last in, first out

A first-in-last-out structure follows an ordering rule in which the most recently added item is the first retrieved, processed, or removed.

How 3 Manning books explain it

Classic Computer Science Problems in Swift: Essential techniques for practicing programmers

Last-in-first-out is an access-ordering rule in which the most recently inserted item is removed first.

How it is used
Uses LIFO stacks to model Towers of Hanoi and drive depth-first maze search.
How deep it goes
Explains the ordering rule, implements push, pop, and isEmpty in Swift, and demonstrates recursive and search-based uses.
Examples
Demonstrates disc towers, recursive Hanoi transfers, and maze exploration with a generic DFS frontier.
What you can do after
Apply it via Swift’s Array to implement stacks for recursive algorithms and depth-first searches.

Read how Classic Computer Science Problems in Swift: Essential techniques for practicing programmers explains first-in-last-out structure →

Algorithms Every Programmer Should Know

LIFO is an ordering rule in which the most recently added element is the first one removed.

How it is used
Organizes elements so the newest addition is the first removed, supporting stacks, function calls, undo and redo, and depth-first search.
How deep it goes
Defines LIFO, traces a four-number example, names stack operations and gives their time and space complexity.
Examples
Uses a pancake stack, inserting 3, 4, 6, and 8, function calls, undo and redo, and depth-first search backtracking.
What you can do after
Apply LIFO with a stack to support depth-first search, function calls, recursion, and undo or redo operations.

Read how Algorithms Every Programmer Should Know explains first-in-last-out structure →

High Performance Unity Game Development

An ordering discipline in which the most recently added item is the first removed.

How it is used
Explains how allocation and deallocation order affects memory use and performance in C#.
How deep it goes
Defines stack storage as LIFO, contrasts heap fragmentation, and notes that Unity's garbage collector can fragment memory even with reverse-order deallocation.
Examples
Uses three differently sized arrays to show how two separate free holes block a larger allocation.
What you can do after
Understand why fragmented free memory can prevent an allocation despite sufficient total space.

Read how High Performance Unity Game Development explains first-in-last-out structure →

Also covered in

What to know first

Related concepts

Questions about first-in-last-out structure

What is first-in-last-out structure?

A first-in-last-out structure follows an ordering rule in which the most recently added item is the first retrieved, processed, or removed.

Which Manning books explain first-in-last-out structure?

Classic Computer Science Problems in Swift: Essential techniques for practicing programmers, Algorithms Every Programmer Should Know and High Performance Unity Game Development.

What should I know before learning first-in-last-out structure?

Manning books that teach first-in-last-out structure usually introduce garbage collection, heap and array first.

What is the difference between first-in-last-out structure and queue?

A first-in-last-out structure follows an ordering rule in which the most recently added item is the first retrieved, processed, or removed. A queue is an ordered collection that holds items for retrieval or processing, commonly in first-in, first-out order.

What is first-in-last-out structure also called?

First-in-last-out structure is also called LIFO or last in, first out.

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.