liveBook · Manning

Push

As explained in Grokking Data Structures

A push method is a stack operation that adds an element to the top of the stack.

Picture a pile of dishes: push places a new element on top, so it becomes the first element available to remove. This is the stack’s insertion operation under the LIFO policy. section 8.3 section 8.19

A push operation follows a small set of practical rules:

  • Adds only at the top of the stack; arbitrary insertion is not part of the stack interface. section 8.3
  • Makes the new element the next candidate for pop, preserving last-in, first-out order. section 8.19
  • Can validate values before insertion, such as rejecting an empty string in a string stack. section 8.10
def push(self, value):
    self._data.insert_in_front(value)

A linked-list-backed stack can implement push by forwarding insertion to the list’s front, reusing tested storage logic. section 8.10

How Grokking Data Structures covers it

How deep it goes
Explains top insertion, linked-list delegation, and optional validation without detailing lower-level storage mechanics.
Examples
Uses a pile of dishes, a linked-list wrapper, and rejection of empty strings as concrete illustrations.
What it assumes
Assumes only the stack’s top and LIFO behavior, while illustrating implementation through a linked list.
What you can do after
Build it by forwarding insertion to a linked list and adding domain-specific checks before storage.
How it connects
Connects push with stacks, LIFO order, linked lists, pop, and peek.

Also explained in

Compare how 4 books explain push →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Data Structures. The section links point to the parts of the book it draws on.