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

Write a code in java. public static lp reverse(lp head) If the input is empty re

ID: 3612836 • Letter: W

Question

Write a code in java. public static lp reverse(lp head) If the input is empty return null otherwise use a recursivecall to reverse the list.head.rest. then use the append function to add head.first to the end of the reversed list. The second argument of appendis a list not a number.But you can make a list of lengthone,containing only the number head.first. then you can use appendto add this list to the end of another list The user should see input positive integers 5,3,8,2, reverse 2 8 9 5 Write a code in java. public static lp reverse(lp head) If the input is empty return null otherwise use a recursivecall to reverse the list.head.rest. then use the append function to add head.first to the end of the reversed list. The second argument of appendis a list not a number.But you can make a list of lengthone,containing only the number head.first. then you can use appendto add this list to the end of another list The user should see input positive integers 5,3,8,2, reverse 2 8 9 5

Explanation / Answer

import java.util.*;
public class lp
{
   public int first;
   public lp rest;
   public lp(int first, lp rest)
{
   this.rest = rest;
   this.first = first;
}
public static String toString(lp head)

{
String str = Integer.toString(head.first);
if (head.rest != null) str += " " +toString(head.rest);
return str;
}
public static lp append(lp head1, lp head2)
{
if(head1==null){
return head2;
}
else

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