Question: ( Java ) Help find the problem of the code, I couldn't get the reverse list right in my test Here is the code: private

( Java ) Help find the problem of the code, I couldn't get the reverse list right in my test

Here is the code:

private BasicLinkedList ReverseListAuxiliary(Node curr, Node prev){

if (curr.next == null) {

head = curr;

/* Update next to prev node */

curr.next = prev;

return null;

}

/* Save curr.next node for recursive call */

Node next1 = curr.next;

/* and update next ..*/

curr.next = prev;

return new BasicLinkedList().addToEnd((T)ReverseListAuxiliary(next1, curr));

}

public BasicLinkedList getReverseList(){

return ReverseListAuxiliary(head, null);

}

}

Here is the test code:

@Test

public void basicLinkedLIstReverse() {

BasicLinkedList list1 = new BasicLinkedList ();

list1.addToEnd("Hello").addToEnd("World").addToEnd("Mike");

list1.getReverseList();

assertEquals("Mike", list1.getFirst());

assertEquals("Hello", list1.getLast());

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!