SlideShare a Scribd company logo
1 of 2
Download to read offline
The algorithm to reverse a linked list by rearranging the required pointers is given as follows:
The pseudo-code to show the working of the algorithm is given as follows:
//Define the function to reverse a list.
node* reverseList(node* head)
{
//Declare and initialize the required pointer variables.
node* prev_node;
node* cur_node;
node* next_node;
prev_node = NULL;
next_node = NULL;
cur_node = head;
//Traverse the whole list using while loop.
while(cur_node != NULL)
{
//Rearrange the pointers to reverse the list.
next_node = cur_node->next;
cur_node->next = prev_node;
prev_node = cur_node;
cur_node = next_node;
}
//Make the recent previous node as head of the list.
head = prev_node;
//Return the head of the list.
return head;
}
Solution
The algorithm to reverse a linked list by rearranging the required pointers is given as follows:
The pseudo-code to show the working of the algorithm is given as follows:
//Define the function to reverse a list.
node* reverseList(node* head)
{
//Declare and initialize the required pointer variables.
node* prev_node;
node* cur_node;
node* next_node;
prev_node = NULL;
next_node = NULL;
cur_node = head;
//Traverse the whole list using while loop.
while(cur_node != NULL)
{
//Rearrange the pointers to reverse the list.
next_node = cur_node->next;
cur_node->next = prev_node;
prev_node = cur_node;
cur_node = next_node;
}
//Make the recent previous node as head of the list.
head = prev_node;
//Return the head of the list.
return head;
}

More Related Content

Similar to The algorithm to reverse a linked list by rearranging the required p.pdf

1) Create a function called reverselist that will take a simple list.pdf
1) Create a function called reverselist that will take a simple list.pdf1) Create a function called reverselist that will take a simple list.pdf
1) Create a function called reverselist that will take a simple list.pdf
ivylinvaydak64229
 
Use C++ Write a function to merge two doubly linked lists. The input.pdf
Use C++ Write a function to merge two doubly linked lists. The input.pdfUse C++ Write a function to merge two doubly linked lists. The input.pdf
Use C++ Write a function to merge two doubly linked lists. The input.pdf
shalins6
 
Mi 103 linked list
Mi 103 linked listMi 103 linked list
Mi 103 linked list
Amit Vats
 
Below is a depiction of a doubly-linked list implementation of the bag.docx
Below is a depiction of a doubly-linked list implementation of the bag.docxBelow is a depiction of a doubly-linked list implementation of the bag.docx
Below is a depiction of a doubly-linked list implementation of the bag.docx
gilliandunce53776
 
in Java (ignore the last line thats hidden) Create a doubly linked l.pdf
in Java (ignore the last line thats hidden) Create a doubly linked l.pdfin Java (ignore the last line thats hidden) Create a doubly linked l.pdf
in Java (ignore the last line thats hidden) Create a doubly linked l.pdf
sauravmanwanicp
 
Write a program in C that does the followinga) Builds a simple li.pdf
Write a program in C that does the followinga) Builds a simple li.pdfWrite a program in C that does the followinga) Builds a simple li.pdf
Write a program in C that does the followinga) Builds a simple li.pdf
kavithaarp
 
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdfC++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
poblettesedanoree498
 
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdfC++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
callawaycorb73779
 
Write a C++ function that delete nodes in a doubly linkedlist- It shou.docx
Write a C++ function that delete nodes in a doubly linkedlist- It shou.docxWrite a C++ function that delete nodes in a doubly linkedlist- It shou.docx
Write a C++ function that delete nodes in a doubly linkedlist- It shou.docx
noreendchesterton753
 
Javai have to make a method that takes a linked list and then retu.pdf
Javai have to make a method that takes a linked list and then retu.pdfJavai have to make a method that takes a linked list and then retu.pdf
Javai have to make a method that takes a linked list and then retu.pdf
stopgolook
 
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdfInspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
vishalateen
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdf
EricvtJFraserr
 
Implement the following specification of UnsortedType using circular.pdf
Implement the following specification of UnsortedType using circular.pdfImplement the following specification of UnsortedType using circular.pdf
Implement the following specification of UnsortedType using circular.pdf
udit652068
 
could you implement this function please, im having issues with it..pdf
could you implement this function please, im having issues with it..pdfcould you implement this function please, im having issues with it..pdf
could you implement this function please, im having issues with it..pdf
feroz544
 
Lec3-Linked list.pptx
Lec3-Linked list.pptxLec3-Linked list.pptx
Lec3-Linked list.pptx
FaheemMahmood2
 

Similar to The algorithm to reverse a linked list by rearranging the required p.pdf (20)

1) Create a function called reverselist that will take a simple list.pdf
1) Create a function called reverselist that will take a simple list.pdf1) Create a function called reverselist that will take a simple list.pdf
1) Create a function called reverselist that will take a simple list.pdf
 
Use C++ Write a function to merge two doubly linked lists. The input.pdf
Use C++ Write a function to merge two doubly linked lists. The input.pdfUse C++ Write a function to merge two doubly linked lists. The input.pdf
Use C++ Write a function to merge two doubly linked lists. The input.pdf
 
Mi 103 linked list
Mi 103 linked listMi 103 linked list
Mi 103 linked list
 
C Homework Help
C Homework HelpC Homework Help
C Homework Help
 
Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]
 
Below is a depiction of a doubly-linked list implementation of the bag.docx
Below is a depiction of a doubly-linked list implementation of the bag.docxBelow is a depiction of a doubly-linked list implementation of the bag.docx
Below is a depiction of a doubly-linked list implementation of the bag.docx
 
in Java (ignore the last line thats hidden) Create a doubly linked l.pdf
in Java (ignore the last line thats hidden) Create a doubly linked l.pdfin Java (ignore the last line thats hidden) Create a doubly linked l.pdf
in Java (ignore the last line thats hidden) Create a doubly linked l.pdf
 
Write a program in C that does the followinga) Builds a simple li.pdf
Write a program in C that does the followinga) Builds a simple li.pdfWrite a program in C that does the followinga) Builds a simple li.pdf
Write a program in C that does the followinga) Builds a simple li.pdf
 
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdfC++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
 
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdfC++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
 
Linked lists in Data Structure
Linked lists in Data StructureLinked lists in Data Structure
Linked lists in Data Structure
 
C Exam Help
C Exam Help C Exam Help
C Exam Help
 
Write a C++ function that delete nodes in a doubly linkedlist- It shou.docx
Write a C++ function that delete nodes in a doubly linkedlist- It shou.docxWrite a C++ function that delete nodes in a doubly linkedlist- It shou.docx
Write a C++ function that delete nodes in a doubly linkedlist- It shou.docx
 
Javai have to make a method that takes a linked list and then retu.pdf
Javai have to make a method that takes a linked list and then retu.pdfJavai have to make a method that takes a linked list and then retu.pdf
Javai have to make a method that takes a linked list and then retu.pdf
 
Lec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdfLec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdf
 
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdfInspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdf
 
Implement the following specification of UnsortedType using circular.pdf
Implement the following specification of UnsortedType using circular.pdfImplement the following specification of UnsortedType using circular.pdf
Implement the following specification of UnsortedType using circular.pdf
 
could you implement this function please, im having issues with it..pdf
could you implement this function please, im having issues with it..pdfcould you implement this function please, im having issues with it..pdf
could you implement this function please, im having issues with it..pdf
 
Lec3-Linked list.pptx
Lec3-Linked list.pptxLec3-Linked list.pptx
Lec3-Linked list.pptx
 

More from aradhana9856

Interest.javaimport java.util.Scanner; public class Interest.pdf
 Interest.javaimport java.util.Scanner; public class Interest.pdf Interest.javaimport java.util.Scanner; public class Interest.pdf
Interest.javaimport java.util.Scanner; public class Interest.pdf
aradhana9856
 
1) The Arrhenius Theory of acids and bases Acids are substances wh.pdf
  1) The Arrhenius Theory of acids and bases  Acids are substances wh.pdf  1) The Arrhenius Theory of acids and bases  Acids are substances wh.pdf
1) The Arrhenius Theory of acids and bases Acids are substances wh.pdf
aradhana9856
 
(i) Deques cannot be implemented using arrays. false    Justif.pdf
(i) Deques cannot be implemented using arrays.  false    Justif.pdf(i) Deques cannot be implemented using arrays.  false    Justif.pdf
(i) Deques cannot be implemented using arrays. false    Justif.pdf
aradhana9856
 
We all know humans are good at removing the competition and it is di.pdf
We all know humans are good at removing the competition and it is di.pdfWe all know humans are good at removing the competition and it is di.pdf
We all know humans are good at removing the competition and it is di.pdf
aradhana9856
 
Theories devised by keynes and Minsky are similar in concept since M.pdf
Theories devised by keynes and Minsky are similar in concept since M.pdfTheories devised by keynes and Minsky are similar in concept since M.pdf
Theories devised by keynes and Minsky are similar in concept since M.pdf
aradhana9856
 
Terry And Hill can develop a method of profit sharing on below facto.pdf
Terry And Hill can develop a method of profit sharing on below facto.pdfTerry And Hill can develop a method of profit sharing on below facto.pdf
Terry And Hill can develop a method of profit sharing on below facto.pdf
aradhana9856
 
Splicing mechanismSmall nuclear ribonucleic acid (snRNA) It is al.pdf
Splicing mechanismSmall nuclear ribonucleic acid (snRNA) It is al.pdfSplicing mechanismSmall nuclear ribonucleic acid (snRNA) It is al.pdf
Splicing mechanismSmall nuclear ribonucleic acid (snRNA) It is al.pdf
aradhana9856
 
PresentationThe capability of enormous information - or the new .pdf
PresentationThe capability of enormous information - or the new .pdfPresentationThe capability of enormous information - or the new .pdf
PresentationThe capability of enormous information - or the new .pdf
aradhana9856
 

More from aradhana9856 (20)

First lets draw out the Lewis structure such that each atom has.pdf
 First lets draw out the Lewis structure such that each atom has.pdf First lets draw out the Lewis structure such that each atom has.pdf
First lets draw out the Lewis structure such that each atom has.pdf
 
Interest.javaimport java.util.Scanner; public class Interest.pdf
 Interest.javaimport java.util.Scanner; public class Interest.pdf Interest.javaimport java.util.Scanner; public class Interest.pdf
Interest.javaimport java.util.Scanner; public class Interest.pdf
 
13. The answer is C. 34Let D be the dominant allele and d be the.pdf
13. The answer is C. 34Let D be the dominant allele and d be the.pdf13. The answer is C. 34Let D be the dominant allele and d be the.pdf
13. The answer is C. 34Let D be the dominant allele and d be the.pdf
 
1) The Arrhenius Theory of acids and bases Acids are substances wh.pdf
  1) The Arrhenius Theory of acids and bases  Acids are substances wh.pdf  1) The Arrhenius Theory of acids and bases  Acids are substances wh.pdf
1) The Arrhenius Theory of acids and bases Acids are substances wh.pdf
 
1. Coenzyme A - C. A water soluble acyl group carrier.2. Thiamine .pdf
1. Coenzyme A - C. A water soluble acyl group carrier.2. Thiamine .pdf1. Coenzyme A - C. A water soluble acyl group carrier.2. Thiamine .pdf
1. Coenzyme A - C. A water soluble acyl group carrier.2. Thiamine .pdf
 
Using Clausius-Clapeyron relation Ln(P2P1) = (D.pdf
                     Using Clausius-Clapeyron relation Ln(P2P1) = (D.pdf                     Using Clausius-Clapeyron relation Ln(P2P1) = (D.pdf
Using Clausius-Clapeyron relation Ln(P2P1) = (D.pdf
 
purines are double ringed nitrogenous bases of DN.pdf
                     purines are double ringed nitrogenous bases of DN.pdf                     purines are double ringed nitrogenous bases of DN.pdf
purines are double ringed nitrogenous bases of DN.pdf
 
(i) Deques cannot be implemented using arrays. false    Justif.pdf
(i) Deques cannot be implemented using arrays.  false    Justif.pdf(i) Deques cannot be implemented using arrays.  false    Justif.pdf
(i) Deques cannot be implemented using arrays. false    Justif.pdf
 
no reaction note 1-butanol is a primary alcohol.pdf
                     no reaction  note 1-butanol is a primary alcohol.pdf                     no reaction  note 1-butanol is a primary alcohol.pdf
no reaction note 1-butanol is a primary alcohol.pdf
 
What type of variable is number of people in the roomNominal.pdf
What type of variable is number of people in the roomNominal.pdfWhat type of variable is number of people in the roomNominal.pdf
What type of variable is number of people in the roomNominal.pdf
 
What is the oxidation number for oxygen in H2O2; for OF2 Explain..pdf
What is the oxidation number for oxygen in H2O2; for OF2  Explain..pdfWhat is the oxidation number for oxygen in H2O2; for OF2  Explain..pdf
What is the oxidation number for oxygen in H2O2; for OF2 Explain..pdf
 
We all know humans are good at removing the competition and it is di.pdf
We all know humans are good at removing the competition and it is di.pdfWe all know humans are good at removing the competition and it is di.pdf
We all know humans are good at removing the competition and it is di.pdf
 
Theories devised by keynes and Minsky are similar in concept since M.pdf
Theories devised by keynes and Minsky are similar in concept since M.pdfTheories devised by keynes and Minsky are similar in concept since M.pdf
Theories devised by keynes and Minsky are similar in concept since M.pdf
 
They might have consumed cyanide.The pit of Apricot contains cyani.pdf
They might have consumed cyanide.The pit of Apricot contains cyani.pdfThey might have consumed cyanide.The pit of Apricot contains cyani.pdf
They might have consumed cyanide.The pit of Apricot contains cyani.pdf
 
The attacking of the nucleophile formed in the reactionof acetone an.pdf
The attacking of the nucleophile formed in the reactionof acetone an.pdfThe attacking of the nucleophile formed in the reactionof acetone an.pdf
The attacking of the nucleophile formed in the reactionof acetone an.pdf
 
Terry And Hill can develop a method of profit sharing on below facto.pdf
Terry And Hill can develop a method of profit sharing on below facto.pdfTerry And Hill can develop a method of profit sharing on below facto.pdf
Terry And Hill can develop a method of profit sharing on below facto.pdf
 
Splicing mechanismSmall nuclear ribonucleic acid (snRNA) It is al.pdf
Splicing mechanismSmall nuclear ribonucleic acid (snRNA) It is al.pdfSplicing mechanismSmall nuclear ribonucleic acid (snRNA) It is al.pdf
Splicing mechanismSmall nuclear ribonucleic acid (snRNA) It is al.pdf
 
since both are strong acids we can add up their individual contribut.pdf
since both are strong acids we can add up their individual contribut.pdfsince both are strong acids we can add up their individual contribut.pdf
since both are strong acids we can add up their individual contribut.pdf
 
public int getPosition(T anObject) { int result = null; result .pdf
public int getPosition(T anObject) { int result = null;  result .pdfpublic int getPosition(T anObject) { int result = null;  result .pdf
public int getPosition(T anObject) { int result = null; result .pdf
 
PresentationThe capability of enormous information - or the new .pdf
PresentationThe capability of enormous information - or the new .pdfPresentationThe capability of enormous information - or the new .pdf
PresentationThe capability of enormous information - or the new .pdf
 

Recently uploaded

Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
AnaAcapella
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111
 
What is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxWhat is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptx
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Play hard learn harder: The Serious Business of Play
Play hard learn harder:  The Serious Business of PlayPlay hard learn harder:  The Serious Business of Play
Play hard learn harder: The Serious Business of Play
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Introduction to TechSoup’s Digital Marketing Services and Use Cases
Introduction to TechSoup’s Digital Marketing  Services and Use CasesIntroduction to TechSoup’s Digital Marketing  Services and Use Cases
Introduction to TechSoup’s Digital Marketing Services and Use Cases
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 

The algorithm to reverse a linked list by rearranging the required p.pdf

  • 1. The algorithm to reverse a linked list by rearranging the required pointers is given as follows: The pseudo-code to show the working of the algorithm is given as follows: //Define the function to reverse a list. node* reverseList(node* head) { //Declare and initialize the required pointer variables. node* prev_node; node* cur_node; node* next_node; prev_node = NULL; next_node = NULL; cur_node = head; //Traverse the whole list using while loop. while(cur_node != NULL) { //Rearrange the pointers to reverse the list. next_node = cur_node->next; cur_node->next = prev_node; prev_node = cur_node; cur_node = next_node; } //Make the recent previous node as head of the list. head = prev_node; //Return the head of the list. return head; } Solution The algorithm to reverse a linked list by rearranging the required pointers is given as follows: The pseudo-code to show the working of the algorithm is given as follows: //Define the function to reverse a list. node* reverseList(node* head) { //Declare and initialize the required pointer variables.
  • 2. node* prev_node; node* cur_node; node* next_node; prev_node = NULL; next_node = NULL; cur_node = head; //Traverse the whole list using while loop. while(cur_node != NULL) { //Rearrange the pointers to reverse the list. next_node = cur_node->next; cur_node->next = prev_node; prev_node = cur_node; cur_node = next_node; } //Make the recent previous node as head of the list. head = prev_node; //Return the head of the list. return head; }