View on GitHub

reading-notes

Stacks and Queues

Stack

A stack is a linear data structure consists of Nodes. Each Node references the next Node in the stack in which elements can be inserted and deleted only from one side of the list.

Common terminology for a stack is

  1. Push.
  2. Pop.
  3. Top.

  1. 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.

  2. IsEmpty - returns true when stack is empty otherwise returns false.

Queue

A queue is a linear data structure in which elements can be inserted only from one side of the list called rear, and the elements can be deleted only from the other side called the front.

Common terminology for a queue is

  1. Front - This is the front/first Node of the queue.
  2. Rear - This is the rear/last Node of the queue.
  3. Peek - When you peek you will view the value of the front Node in the queue. If called when the queue is empty an exception will be raised.
  4. IsEmpty - returns true when queue is empty otherwise returns false.