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.
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.
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
- Grokking AI Algorithms, Second Edition
- Grokking Data Structures
- C# Concurrency: Asynchronous and multithreaded programming
- Think Distributed Systems
What to know first
- garbage collectionGarbage collection is an automated process that identifies and reclaims or removes memory, data, or other items no longer reachable or needed by a system.
- heapA heap is a runtime memory region from which dynamically allocated data is obtained and whose allocation and lifetime are managed separately from function call frames.
- arrayAn array is an ordered collection of elements organized in one or more dimensions and accessible by position or index.
Related concepts
- stackimplemented by · A stack is a last-in, first-out data structure in which elements are added and removed at the same end.
- call stackused by · A call stack is a runtime LIFO structure that tracks active function or method calls, including their execution contexts and return information.
- queuecontrasts with · A queue is an ordered collection that holds items for retrieval or processing, commonly in first-in, first-out order.
- stack memoryused by · Stack memory is runtime memory used to store function-call frames and associated values, typically reclaimed as calls return.
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.


