Stack
A stack is a last-in, first-out data structure in which elements are added and removed at the same end.
Classic Computer Science Problems in Swift: Essential techniques for practicing programmers
A stack is a last-in-first-out data structure in which insertion and removal occur at the same end.
- How it is used
- Models top-only disc moves and holds the frontier of a depth-first maze search.
- How deep it goes
- Defines LIFO, implements a generic Array-backed stack, and addresses empty pops; stops short of enforcing Hanoi’s disc-size rule.
- Examples
- Uses Towers of Hanoi disc transfers and a maze-search frontier.
- What you can do after
- Build it from scratch as a generic Swift Array-backed stack and apply it to Hanoi moves or a depth-first frontier.
Grokking Data Structures
Stack is the book's class that implements a stack interface by wrapping an underlying linked list.
- How it is used
- Uses a LIFO container to handle the most recent entry first in expression evaluation, undo, and path retracing.
- How deep it goes
- Defines the interface, develops a Python linked-list wrapper, compares storage costs, and examines peek pitfalls.
- Examples
- Illustrates LIFO with dishes and patient forms, then works through postfix evaluation, undo/redo, and game-path retracing.
- What you can do after
- Build it from scratch as a Python wrapper around a singly linked list and choose it when latest-first access fits.
Get Programming: Learn to code with Python
A data structure in which elements are added and removed from the same end, so the most recently added element is removed first.
- How it is used
- Uses a stack to organize items so the newest item is removed first.
- How deep it goes
- Defines a list-backed Stack class and demonstrates its methods with strings and objects.
- Examples
- Uses pancake flavors and Circle objects to demonstrate adding, removing, and storing items.
- What you can do after
- Build it from scratch with a Python class that stores items in a list and provides stack operations.
Read how Get Programming: Learn to code with Python explains stack →
Embedded Software with Rust
A stack is a last-in, first-out memory structure used for nested execution state and temporary data.
- How it is used
- Guides RAM placement and stack-overflow prevention in resource-constrained embedded firmware.
- How deep it goes
- Explains frame contents, stack-pointer movement, startup placement, and overflow risks; identifies detection and prevention tools.
- Examples
- Uses a Cortex-M vector-table linker fragment and a recursive function that can corrupt static data.
- What you can do after
- Evaluate stack placement and overflow risks when choosing how firmware uses limited RAM.
.NET in Action, Second Edition
A stack is a runtime memory region that stores function-local variables, arguments, and return addresses using call-order allocation.
- How it is used
- Connects active method calls to CPU profiling and distinguishes call storage from dynamic heap allocation.
- How deep it goes
- Explains frames, call-and-return behavior, stored data, and overflow without detailing byte-level frame layout.
- Examples
- Uses a nested method-call diagram and C++ and C# runtime-sized array listings.
- What you can do after
- Diagnose/debug with it by interpreting profiled call frames and recognizing recursion-driven stack overflow.
Fabulous Adventures in Data Structures and Algorithms
A stack is a last-in, first-out data structure supporting insertion and removal at one end.
- How it is used
- Uses explicit stacks to track pending work in nonrecursive pretty-printing algorithms.
- How deep it goes
- Works through two stack-based traversals, including loop termination, width checks, and per-task state; does not implement a stack collection.
- Examples
- Uses C# Fits and Pretty methods to show stacks of documents and tuples carrying formatting state.
- What you can do after
- Build it from scratch as a nonrecursive document traversal using an existing Stack collection.
Read how Fabulous Adventures in Data Structures and Algorithms explains stack →
Modern C
A stack is a last-in, first-out data structure in which values are added and removed at one end.
- How it is used
- Uses the stack to explain intermediate-value algorithms and the memory state established for C function execution.
- How deep it goes
- Explains stack-frame setup, register roles, offsets, and uninitialized reserved space, but stops short of a broader stack interface.
- Examples
- Traces fgoto through assembler instructions that save %rbp, establish a frame, reserve 48 bytes, and initialize local variables.
- What you can do after
- Evaluate assembler output by locating function data through stack-pointer setup, base-pointer offsets, and register movements.
Refactoring to Rust
A stack is a last-in-first-out memory region or abstract data structure used for values such as function-call state and local variables.
- How it is used
- Organizes local variables and function-call data during program execution.
- How deep it goes
- Defines stack behavior, capacity, and contrast with heap storage without detailing implementation internals.
- Examples
- Uses a welcome function and patron name to illustrate local values, allocation, and memory cleanup.
- What you can do after
- Evaluate/understand whether data belongs conceptually on the stack or heap.
Modern C, Third Edition
A stack is a last-in, first-out storage structure in which function-call contexts are added and removed as calls and returns occur.
- How it is used
- Models function-call storage and explains how local objects occupy machine-level stack frames.
- How deep it goes
- Explains push-and-pop behavior, registers, offsets, recursion, and VLA risks, but notes that C provides no tool to predict stack exhaustion.
- Examples
- Uses the fgoto assembly listing, stack-frame offsets, unbounded recursion, and variable-length arrays as concrete cases.
- What you can do after
- Evaluate assembly stack-frame setup and recognize recursion or variable-length arrays as potential sources of stack overflow.
Algorithms Every Programmer Should Know
A stack is a last-in-first-out data structure that adds and removes elements at one end.
- How it is used
- Models last-in, first-out access for operations such as function calls and undo/redo.
- How deep it goes
- Defines LIFO, demonstrates push, pop, and peek, and gives operation and space costs without analyzing implementation internals.
- Examples
- Uses a pancake analogy, a sequence of values, function calls, and undo/redo to illustrate stack behavior.
- What you can do after
- Build it from scratch with a Python list, including empty-stack checks for pop and peek.
Read how Algorithms Every Programmer Should Know explains stack →
Functional Programming in JavaScript
A last-in, first-out data structure in which elements are added and removed from one end called the top.
- How it is used
- Explains function execution, nested calls, and memory growth in JavaScript.
- How deep it goes
- Defines LIFO and traces frame creation, scope links, memory use, nesting, currying, and recursion.
- Examples
- Uses a dish pile, logger invocation, recursive increment, and longest-string recursion to illustrate stack behavior.
- What you can do after
- Evaluate how JavaScript calls pause, resume, allocate frames, and grow the execution stack.
Read how Functional Programming in JavaScript explains stack →
Applied Reinforcement Learning
A stack is a data structure that processes elements in last-in, first-out order.
- How it is used
- Supports depth-first search by keeping the newest node ready to explore.
- How deep it goes
- Defines LIFO behavior and relates it to DFS recursion, without detailing stack internals.
- Examples
- Demonstrates recursive depth-first exploration of customer routes and backtracking.
- What you can do after
- Apply recursion to explore a search tree deeply before backtracking.
Latency
A stack is a memory region that supports function execution by storing call state, registers, return information, and local data.
- How it is used
- Supports function execution and provides constant-time boundary operations for latency-sensitive data handling.
- How deep it goes
- Explains stack frames, saved registers, return information, address growth, and lazy allocation, but defers architecture-specific implementation details.
- Examples
- Uses function calls, local variables, saved registers, return information, and process-memory diagrams as examples.
- What you can do after
- Evaluate stack suitability by relating function-execution behavior and insertion, deletion, and search complexity to latency-sensitive workloads.
Advanced Algorithms and Data Structures
A stack is a container abstraction in which removal returns the most recently inserted element that remains, following last-in-first-out order.
- How it is used
- Models last-in-first-out storage and supplies the traversal container for depth-first search.
- How deep it goes
- Defines insertion and removal, then frames representation choices without specifying a complete concrete implementation.
- Examples
- Uses piles of files or dishes and depth-first search with backtracking as concrete illustrations.
- What you can do after
- Apply a stack as the container that drives depth-first traversal and backtracking.
Read how Advanced Algorithms and Data Structures explains stack →
Grokking AI Algorithms, Second Edition
A stack is a linear data structure in which elements are added and removed from the same end.
- How it is used
- Uses a LIFO stack to drive depth-first search through nodes and maze positions.
- How deep it goes
- Defines LIFO and traces stack operations through DFS, including visited checks, goal tests, and backtracking.
- Examples
- Demonstrates root-node search, maze movement, neighbor processing, and a DFS implementation listing.
- What you can do after
- Build it from scratch by initializing, popping, checking, and appending items in a DFS stack.
Read how Grokking AI Algorithms, Second Edition explains stack →
Learn Rust in a Month of Lunches
The stack is a memory region that stores values with a known size and releases them in last-in, first-out order as execution leaves scopes or functions.
- How it is used
- Explains how Rust stores values and releases memory while introducing memory, variables, and ownership.
- How deep it goes
- Defines speed, last-in-first-out release, compile-time sizing, heap pointers, and embedded limitations without detailing implementation internals.
- Examples
- Uses a stack of dishes, an i32 value, heap data with a stack pointer, and a small embedded device.
- What you can do after
- Understand why some Rust values use the stack and how pointers connect stack locations to heap data.
Optimization Algorithms: AI techniques for design, planning, and control problems
A last-in, first-out data structure in which elements are added to and removed from the same end.
- How it is used
- Supports depth-first search by prioritizing the most recently discovered node and enabling backtracking through a graph.
- How deep it goes
- Explains initialization, push and pop operations, successor filtering, and termination within DFS, without examining implementation internals.
- Examples
- Uses depth-first search on the 8-puzzle and path-planning problems to demonstrate stack-based exploration.
- What you can do after
- Apply it via depth-first search to prioritize deep graph exploration and return to earlier decision points after dead ends.
Also covered in
- The Well-Grounded Rubyist, Fourth Edition
- .NET MAUI in Action
- High Performance Unity Game DevelopmentIn early access (MEAP)
- Code Like a Pro in Rust
- Classic Game Programming on the NES: Make your own retro video game
- Machine Learning Algorithms in Depth
- Python Concurrency with asyncio
- Grokking Algorithms, Second Edition
- Think Distributed Systems
- Regular Expression Puzzles and AI Coding Assistants
What to know first
- arrayAn array is an ordered collection of elements organized in one or more dimensions and accessible by position or index.
- primitive typeA primitive type is a predefined basic data type representing a simple value rather than a composite structure of multiple values or fields.
- memoryMemory is a storage capability or mechanism for retaining information or computational state for later access or use.
- data structureA data structure is an organized representation of data and its relationships that supports defined operations for storing, accessing, or modifying it.
Related concepts
- depth-first searchused by · Depth-first search is a traversal strategy that follows a branch as far as possible before backtracking to explore alternatives.
- call stackincludes · 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.
- first-in-last-out structureimplements · A first-in-last-out structure follows an ordering rule in which the most recently added item is the first retrieved, processed, or removed.
- circular queuecontrasts with · A circular queue is a queue whose storage positions wrap from the end to the beginning, allowing items to be added and removed without shifting remaining elements.
Questions about stack
What is stack?
A stack is a last-in, first-out data structure in which elements are added and removed at the same end.
Which Manning books explain stack?
Classic Computer Science Problems in Swift: Essential techniques for practicing programmers, Grokking Data Structures, Get Programming: Learn to code with Python, Embedded Software with Rust, .NET in Action, Second Edition, Fabulous Adventures in Data Structures and Algorithms, Modern C, Refactoring to Rust and 9 more.
What should I know before learning stack?
Manning books that teach stack usually introduce array, primitive type, memory and data structure first.
What is the difference between stack and queue?
A stack is a last-in, first-out data structure in which elements are added and removed at the same end. A queue is an ordered collection that holds items for retrieval or processing, commonly in first-in, first-out order.
What kinds of stack are there?
Kinds of stack include call stack.
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.
















