Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students also viewed these Databases questions