Explain reverse a linked list recursive Java solution?
Submitted by: Muhammadpublic void recursiveReverse(Node currentNode )
{
//check for empty list
if(currentNode == NULL)
return;
/* if we are at the TAIL node:
recursive base case:
*/
if(currentNode.next == NULL)
{
//set HEAD to current TAIL since we are reversing list
head = currentNode;
return; //since this is the base case
}
recursiveReverse(currentNode.next);
currentNode.next.next = currentNode;
currentNode.next = null; //set "old" next pointer to NULL
}
Submitted by: Muhammad
{
//check for empty list
if(currentNode == NULL)
return;
/* if we are at the TAIL node:
recursive base case:
*/
if(currentNode.next == NULL)
{
//set HEAD to current TAIL since we are reversing list
head = currentNode;
return; //since this is the base case
}
recursiveReverse(currentNode.next);
currentNode.next.next = currentNode;
currentNode.next = null; //set "old" next pointer to NULL
}
Submitted by: Muhammad
Read Online Data Structure Linked list Job Interview Questions And Answers
Top Data Structure Linked list Questions
☺ | Suppose In an integer array, there is 1 to 100 number, out of one is duplicate, how to find? |
☺ | What is circular linked list? |
☺ | Explain linked list using C++ with an example? |
☺ | Explain the steps to insert data into a singly linked list? |
☺ | Explain how to find 3rd element from end in a linked list in one pass? |
Top Data Structure Categories
☺ | Data Center Manager Interview Questions. |
☺ | Creative UI/UX Designers Interview Questions. |
☺ | Sort And Searching Interview Questions. |
☺ | Data Structure Linked list Interview Questions. |
☺ | Data Structure Arrays Interview Questions. |