Question: Hello, Please help me correct the error on the line highlighted in yellow public class ReverseDLinkedList. This is the question: Write a method, reverse(), that

Hello, Please help me correct the error on the line highlighted in yellow public class ReverseDLinkedList. This is the question: Write a method, reverse(), that reverses the order of elements in a DLList. NB: I got the solution from: http://www.chegg.com/homework-help/questions-and-answers/write-method-reverse-reverses-order-elements-dllist-q8402183 Method: public class DoublyLinkedListNode { private int value; private DoublyLinkedListNode previous; private DoublyLinkedListNode next; public DoublyLinkedListNode(int v){ this.value = v; this.previous = null; this.next = null; } public void setPrevious(DoublyLinkedListNode prev){ this.previous = prev; } public void setNext(DoublyLinkedListNode n){ this.next = n; } public int getValue(){ return this.value; } public DoublyLinkedListNode getNext(){ return this.next; } public DoublyLinkedListNode getPrevious(){ return this.previous; } } public class ReverseDLinkedList { private static DoublyLinkedListNode tail = null; private static DoublyLinkedListNode head = null; public static void main(String args[]){ for (int i = 0; i < 0; i++){ DoublyLinkedListNode node = new DoublyLinkedListNode(i); if(head == null){ head = node; tail = node; } if (i != 0){ tail.setNext(node); node.setPrevious(tail); tail = node; } } printList(head); System.out.println(""); System.out.println("Reversing the list"); printList(DoublyLinkedListNodeList(head)); } private static DoublyLinkedListNode DoublyLinkedListNodeList(DoublyLinkedListNode head){ DoublyLinkedListNode start = head; DoublyLinkedListNode temp = null; while (head != null){ temp = head.getNext(); head.setNext(head.getPrevious()); head.setPrevious(temp); if (head.getPrevious() == null){ head.setPrevious(start); break; } head = head.getPrevious(); } return head; } private static void printList(DoublyLinkedListNode head){ System.out.println("List: "); while (head != null){ System.out.println(head.getValue() +""); head = head.getNext(); } } } Thanks.

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!