Menu Close

Stack using Linked list

Stack Using Linked List:

  • We can create Stack using single linked list.
  • Generally we use Stack using arrays.
  • Stack using Linked list creation using Nodes.
  • We implement the LIFO(Last In First Out) rule here also.
  • “Top” should point to last node in the list.

Linked List:

Reverse representation:

Represents in the form of Stack:

  • We use the top variable to perform stack operations.
  • Initially top is pointing to NULL.
  • NULL represents “Stack is Empty”
  • The following diagram represents the physical layout of stack with nodes.

Push element on to the Stack:

  • When we push the element, we use top pointer to store the element.
  • Top initial value NULL need to place in the link location of node as we are connecting the nodes in reverse order.

Pop element from Stack:

  • We need to check whether the stack is empty or not while removing the element from Stack.
  • Always we remove the top element from the list.
  • After removal, top is pointing to the next node in the list.