Write a program to reverse a linked list using stack in c++

Question : – Write a program to reverse a linked list using stack in c++

Algorithm

1) Create an empty stack of type node pointer using Standard Template Library(STL).
2) One by one push all the node addresses to stack.
3) One by one pop all the node addresses from stack and rearrange all its link in backward manner.

Program to reverse a linked list using stack

 

 

 

Output

Write a program to reverse a linked list using stack in c++

Suggested Reading

  1. C program to find the middle node of a linked list
  2. Write a c program to implement a queue using array and linked list
  3. Write a c program to implement a stack using an array and linked list