Question: Java double linked list: Follow these instructions: A node class represents a single entry in the list, containing a value, and a next and previous

Java double linked list:

Follow these instructions:

A node class represents a single entry in the list, containing a value, and a next and previous reference. The class should also contain functions for getting and setting values, and joining and severing connections to adjacent Nodes.

The double linked list class manages the overall list, such as creating new lists, adding new nodes to the front and back, removing nodes from the front and back while returning their values, and printing the list both forwards and in reverse.

Node --------------------------------- - previous : Node - next : Node - value : int --------------------------------- + Node (value : int) + joinNext (next : Node) + joinPrevious (previous : Node) + removeNext () + removePrevious () + getNext () : Node + getPrevious () : Node + getValue () : int
DoublyLinkedList ----------------------- - head : Node - tail : Node ----------------------- + prepend (input : int) + append (input : int) + popFront () : int + popBack () : int + printForward () + printReverse ()

The following test code...

List myList = new List(); myList.append(3); myList.append(4); myList.append(5); myList.prepend(2); myList.prepend(1); System.out.println("Print the list forward:"); myList.printForward(); System.out.println(); System.out.println("Print the list backward:"); myList.printReverse(); System.out.println(); System.out.println("Remove and print the first element:"); System.out.println(myList.popFront()); System.out.println("Remove and print the last element:"); System.out.println(myList.popBack()); System.out.println(); System.out.println("Print the list forward:"); myList.printForward(); System.out.println(); System.out.println("Print the list backward:"); myList.printReverse();

should result in output:

Print the list forward: 1 2 3 4 5 Print the list backward: 5 4 3 2 1 Remove and print the first element: 1 Remove and print the last element: 5 Print the list forward: 2 3 4 Print the list backward: 4 3 2

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!