Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can anyone please correct my recursive function code i dont get the problem? pub

ID: 3747262 • Letter: C

Question

Can anyone please correct my recursive function code i dont get the problem?

public class RevList {
/**
   * Reverse a given list.
   * @author list List to be reversed recursively. This list will not be modified.
   * @author Linked list representing reversal of nodes in the input list.
   */
public static SLL reverse(SLL list) {
    SLL revList = new SLL();

    Node newHead;
   
       //base case - tail of original linked list
       if((node.next == null)){
           return node;
       }
       newHead = reverseRecursively(node.next);
   
       //reverse the link e.g. C->D->null will be null     
       node.next.next = node;
       node.next = null;  
       return newHead;
    }

   return revList;
}

}

Explanation / Answer

public class RevList {

// small mistake in your program function name should be same and some syntax error

/**
   * Reverse a given list.
   * @author list List to be reversed recursively. This list will not be modified.
   * @author Linked list representing reversal of nodes in the input list.
   */
public static SLL reverseRecursively(SLL list) {
    SLL revList = new SLL();

    Node newHead;
   
       //base case - tail of original linked list
       if((node.next == null)){
           return node;
       }
       newHead = reverseRecursively(node.next);// function name should be same
   
       //reverse the link e.g. C->D->null will be null     
       node.next.next = node;
       node.next = null;  
       return newHead;
    }//method close

  
} //class close
=============================================================================

correct program

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote