What is stack?

Stack is an Linear data structure which are in commonly used to organize the data. it is named stack as it behaves like a real-world stack, for example- a disk of cards or a pile of plates,etc.
A real-world stack allows operations at one end only For example We can place and remove a card  or plate from the top the stack only  Likewise, Stack ADT(Abstract data type) allows all data operations at one end  only, we can only access the Top  element of a stack.

Some important points.

  •  It is a type of linear data structure.
  • It follows LIFO (Last in First out) property.
  •  it has only one pointer TOP that points the last and top most element of stack.
  • Insertion and Deletion in stack can only be done from TOP only.
  • Insertion in stack is also known as a PUSH operation.
  • Deletion from stack is also known as POP operation in stack.

Basic Operations

Stack is a linear data structure which follows a particular order in which the operations are performed. The order may be LIFO(last in first out).
Mainly the following three basics operations are performed in the stack.

  • PUSH:Adds an item in the stack. if the stack is full,then it is said to be an Overflow condition.
  • POP:Remove an item from 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:Return top elements of stack.

Stack Implementation

  •  Stack implementation using Array.
  • Stack implementation using Link List.
A Stack can be implemented by using Array and Linked List.stack can either be a  fixed size one or it may have a sense of dynamic resizing Here, we are going to implement stack using arrays,which makes it a fixed size stack implementation.

Implementation using Array

implementation using link list

push algorithm

pop algorithm

Leave a Reply

Your email address will not be published. Required fields are marked *