Question: Linked lists are an important, but tricky topic in computer science. What I have tried to do with this code is show you how linked
Linked lists are an important, but tricky topic in computer science. What I have tried to do with this code is show you how linked lists works, while also demonstrating how using classes and helper methods help break up complex tasks into smaller, more manageable ones, while also making your code easier to read, understand, and modify or maintain.
To start:
Example 3 (and the actual file you will need to modify):
- DLLNode.java
- DLList.java
- DLLDriver.java
There are 2 methods in DLList.java for you to implement using the DLLNode.java and DLList.java classes. The DLLDriver.java class will help you test your code.
Write the code in the following methods:
- reverseListv2()
- reverseListString()


DLList.java // The buffer then stores Isaac as the last person processed. When Julia learns that 1/ her next person is Tim, in the same loop iteration, Mikey learns that his previous // person is now Isaac. They continue in this way until the old front of the list is // reached. This becomes the new end of the list, and the list reversal is finished. // Now write a simpler version of a method to reverse a linked list. public void reverselistv20) { // The add method for this class adds items to the FRONT. // So, iterating through from the first to the last node and // adding each node in turn to our new list will end up // reversing the list. // 1. Get the name from the first node in the list. // Use the name string to // construct a new node in a new list "reversedList". 1/ 3. Create a cursor node and point it to front in the original list. // 4. Create a while loop checking foe nextnade. != null. 1/ 5. Iterate through the original list, using the names in the nodes // to create new nodes that you add to the reversedList. // 6. Outside the loop, set this. front to the new list's front. String firstName = front.name; 1/System.out.println(firstName); DLList reversedList = new DLList(firstName); 1/System.out.println(reversedlist.toString()); DLLNode frontCursor = new DLLNode(); frontCursor = this.front; while( frontCursor.nextnode != null) { frontCursor = frontCursor.nextnode; String currName = frontCursor.name; DLLNode cur.Node = new DLLNode(currName); reversedList.addNode(cur.Node); } this. front = reversedList.front; } public String toString() { String toReturn = "front-->"; DLLNode currentF = this.front; while(currentF!= null) { toReturn = toReturn + currentF.nodeString() + "-->" ; current F = current..nextnode; toReturn = toReturn + "back"; return toReturn; } // COMPLETE THE FOLLOWING METHOD THAT RATHER THAN // REVERSING THE LIST, JUST PRODUCES A STRING THAT // ALLOWS THE LIST TO BE PRINTED IN REVERSE ORDER. public String reverseListString() { String toReturn = ""; // YOUR CODE HERE. return toReturn; DLLDriver.java 1 Driver Class for the DOUBLY-LINKED LIST public class DLLDriver { public static void main(String[] args) { DLList myList = new DLList("Isaac"); DLLNode friend1 = new DLLNode ("Mikey"); DLLNode friend2 = new DLLNode("Julia"); myList.addNode(friend1); myList.addNode(friend2); myList.addNode(new DLLNode("Tim")); myList.addNode(new DLLNode("Jon")); // Testing reverse method 1 System.out.println(myList.toString()); mylist..reverselisty1(); System.out.println(myList.toString() ); System.out.println(); // Testing reverse method 2 System.out.println(myList.toString() ); mylist..reverselistv2(); System.out.println(myList.toString() ); System.out.println(); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
