1. Introduction to Stacks #

Created Wednesday 22 January 2020

Every DS has its pros and cons:

  1. Variables can store and acess elements, but not more than one.
  2. Arrays store many variables all at once, but cannot be resized due. This is not applicable to vectors.
  3. Linked list solves the issue of no. of elements, i.e no space is wasted. Non contiguity is allowed. But we cannot go back and forth, in a singly linked list.

We can compare access, insertion and removal for all the possible cases.

Stack is an Abstract Data Type. i.e LIFO(from the elements POV) owill be followed for any operations. Both LL and Arrays can be used here.

Working

Jargon(Stack interface):

  1. push - insertion into the stack
  2. pop - deletes an(the element at top) element and returns the value.
  3. top() - Access the top most element. Returns a copy of the topmost element. No changes made in the stack.
  4. size() - returns number of elements in the stack.
  5. isEmpty() - returns boolean true if stack is empty, else false.