reading-notes

Stacks & Queues

What is a Stack

The basic operations supported by a stack are:

  1. Push adds an element at the top of a stack.

  2. Pop removes the topmost element of a stack

  3. The peek() method returns the element on the top of the stack but does not remove it.

  4. The empty() method returns true if the stack is empty, otherwise, it returns false.

Stacks follow these concepts:

  1. First In Last Out (FILO) : the first item added in the stack will be the last item popped out of the stack.

  2. Last In First Out (LIFO) : the last item added to the stack will be the first item popped out of the stack.

What is a Queue

  1. Enqueue : this method adds an element to the end/rear of the queue

  2. Dequeue : this method removes an element from the front of the queue

  3. Front : Return the front object in the queue, but do not remove it; an error occurs if the queue is empty”

  4. Rear : This is the rear/last Node of the queue.

  5. Peek : This function returns the value of the topmost element available in the stack.

  6. IsEmpty : If the stack is empty, then this function will return a true value or else it will return a false value.

Queues follow these concepts:

  1. First In First Out (FIFO) the element inserted at first in the list, is the first element to be removed from the list.

  2. Last In Last Out (LILO) method for handling data structures where the Last element is processed Last