stack

            STACK INTRODUCTION

  • Push: Adds an item in the stack. If the stack is full, then it is said to be an Overflow condition.
  • Pop: Removes an item from the stack. The items are popped in the reversed order in which they are pushed. If the stack is empty, then it is said to be an Underflow condition.
  • Peek or Top: Returns top element of stack when this function called.
  • isEmpty: Returns true if stack is empty, else return false if stack is not empty.
stack


Time Complexities of operations on stack:
push(), pop(), esEmpty() and peek() all take O(1) time. We do not run any loop in any of these operations.
Implementation:
There are two ways to implement a stack:
  • Using array.
  • Using linked list.

No comments:

Post a Comment