Stack Data Structure

Stack is used to implement LIFO order. LIFO order is used in expression evaluation. So that stack is used to track the operators and operands for expression evaluation.

Stack in daily life

Stack can be observed in our daily life such as following are examples of stack in daily life.

  • Stack of chairs
  • Stack of books
  • Stack of plates

Stack operations

Stack provide the following two operations

  1. Push
  2. Pop

Push operation

The process of saving data onto the stack is known as push operation. The operation is preformed after checking either there is empty memory location in stack. This check is called stack full check. In case of stack implementation using linked list there may no required to check whether is stack is full or not, because linked list is dynamic data structure.

Pop operation

The process of getting the recently inserted data from stack is known as pop operation. Normally SP (Stack Pointer) points to the memory location/position from where data is to be fetched. After successfully pop operation stack pointer is decremented and points to the next memory location from where next value to be fetched. Before every pop operation stack must be check for its empty state. If stack empty state check return true then empty stack message will be displayed and in this situation normally SP will have -1 value

Stack implementation

Stack can be implemented using the following two methods.

  1. Stack using array
  2. Stsck using linked list

Stack using array

We can implement stack with the help of array. For this purpose we have to declare an array of specified size. Next we have to set a variable normally of int type. Which is called stack pointer SP. Initially SP has -1 value which indicate the empty stack. When insertion in stack is performed (Push operation) the SP is first incremented and then value is inserted in next empty memory location. Before every push operation first of all stack is check either stack is full if stack is full then no more data will be pushed onto stack.

Stack using linked list

Stack data structure can also be implemented using linked list. However we have to set the no of data items that a stack can hold. For this purpose we maintain a SP stack pointer similar to stack implementation using array. This SP will be increment or decrement after each push or pop operation. Stack implementation using linked list required more memory than array.

Uses of Stack

Stack has many important uses in computer. Some are listed below.

  1. Expression Evaluation
  2. Recursion
  3. Expression Conversion
  4. Memory Management
  5. Undo/Redo
  6. Backtracking

Stack presentation and structure

Stack in memory is presented in the following way using array and linked list.

Structure in memory depends upon its implementation.

Stack animation

Visual basic animation is deveopled by binaryVisual. We can download visual presentation of stack algorithm using this link.

Login to TRACK of Comments.