Stacks and Queues

201-Your reminder to trust the process!

Stacks and Queues

source: Stacks and Queues – -

What is a Stack?

Common Terms:

  1. Push: Nodes or items that are put into the stack are pushed

  2. Pop: Nodes or items that are removed from the stack are popped. When you attempt to pop an empty stack an
    exception will be raised.
  3. Top: This is the top of the stack.

  4. Peek: When you peek you will view the value of the top Node in the stack. When you attempt to peek an empty stack an exception will be raised.

  5. IsEmpty: returns true when stack is empty otherwise returns false.
    – - FILO:
    • This means that the first item added in the stack will be the last item popped out of the stack.

Stack Visualization

Here’s an example of what a stack looks like. As you can see, the topmost item is denoted as the top.
When you push something to the stack, it becomes the new top. When you pop something from the stack,
you pop the current top and set the next top as top.next.

Stack Visualization