Question: Java please. Youre given the pointer to the head node of a linked list (you will be provided with supporting Java code, the code will

Java please.

Youre given the pointer to the head node of a linked list (you will be provided with supporting Java code, the code will be uploaded to the interact2 site).

Task 2.1 - You need to implement DoublyLinkedListNode and DoublyLinkedList classes. The linkedlist class should implement methods to read data from a file and output data to console (recommend to use java.util.Scanner Java class)

Task 2.2 - You have to complete a reverse (DoublyLinkedListNode head) method which takes one argument - the head of the linked list.

/*

* For your reference:

*

* DoublyLinkedListNode {

* int data;

* DoublyLinkedListNode next;

* DoublyLinkedListNode prev;

* }

*

*/

Input Format

The input format is as follows:

The first line contains an integer t, denoting the number of test cases. Each test case is of the following format:

The first line contains an integer n, denoting the number of elements in the linked list. The next n lines contain an integer each, denoting the elements of the linked list.

Input will be always valid data.

Constrains

  1. 1 <= t<= 10
  2. 1 <= n <= 1000
  3. 1 <= listi <= 1000, where listi is the ith element in the list

Output Format

The output format is as follows:

For each test case, print in a new line the elements of the linked list after reversing it, separated by spaces.

Sample Input

1 5 1 2 3 4 5 

Sample Output

5 4 3 2 1 

Explanation

The initial linked list is: 1 <-> 2 <-> 3 <-> 4 <-> 5 <-> NULL

The reversed linked list is: 5 <-> 4 <-> 3 <-> 2 <-> 1 <-> NULL

You should NOT use java's LinkedList class rather implement your own.

Your implementation should adhere to the above-mentioned sample input/output format.

You need to think about the design of your program to allow code reuse. You should also consider the number of lines in each method; as a guideline, a method should not exceed 25 lines.

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!