Write a function to reverse a linked list

Write a function to reverse a linked list

In this article, we will see how to reverse a linked list in C.

For Example,

 

We can reverse the linked list using two approaches.

  1. Iterative method
  2. Recursive method

Iterative method

This is the simplest way to reverse  linked list, in which we iterate a loop throughout the linked list and change the direction of the link.

Image shows the first Iteration of the loop.

For Example:

 

OutPut:

 

If you want to learn more about the c language, here 10 Free days (up to 200 minutes) C video course for you.

Your free trial is waiting

 

Recursive method

Recursion is also another technique to reverse the linked-list. In recursion, we are used stack memory to reverse the linked list.

 

OutPut:




Leave a Reply