What is Stack ?

What is Stack ?

ยท

2 min read

Stack

  • A stack is a linear data structure, where "linear" refers to the order in which the items are arranged. The two operations that can be performed on a stack data structure are push and pop. Push operation adds an element to the top of the stack, while pop action removes an element from the top of the stack.

  • In stack elements are stored in Last in First Out Order , that means elements are added to the top of the stack and remove from top of the stack.

  • Example - Pile of books

TOP.png

Advantages of Stack

  • It is used in many virtual machines such as jvm.

  • Stacks allows control allocation of memory and deallocation.

  • Stack helps in data management.

  • Stack helps in systematic memory management.

Disadvantages of Stack

  • Stack memory has limited size.

  • Total size must be defined in advance.

  • Random access is not possible on the stack.

  • The stack will fall outside of the memory area, which might lead to an abnormal termination.

Common Stack Operations

  • push(): A push is the action of adding an element to a stack. The overflow circumstance occurs when the stack is full or finished.
  • pop(): Deleting an element from a stack is referred to as a pop. The absence of any element indicates that the stack is empty. The underflow state is what we refer to as here.
  • isFull(): It aids in determining whether or not the stack is full.
  • isEmpty(): This function aids in determining whether or not the stack is empty.

  • peek(): returns the element at the specified location.

  • count(): This function is used to determine how many elements are present in a stack overall.
  • display(): This method is used to print every element in the stack.

Did you find this article valuable?

Support Sayam by becoming a sponsor. Any amount is appreciated!

ย