Interviewer And Interviewee Guide

Data Structure Linked list Interview Question:

Explain reverse a linked list recursive Java solution?

Submitted by: Muhammad
public 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

Read Online Data Structure Linked list Job Interview Questions And Answers
Copyright 2007-2024 by Interview Questions Answers .ORG All Rights Reserved.
https://InterviewQuestionsAnswers.ORG.