CJCoding With Joseph
15free / daySign inCreate account

In a doubly linked list every DNode has a prev link as well as a next link. A new first node therefore needs two links wired, one in each direction, before head moves onto it. addLast is already written and shows the same idea at the other end.

Requirements: 1. addFirst(int value) puts a new node at the front of the list. 2. On an empty list the new node becomes both head and tail. 3. Otherwise the new node points forward at the old head, the old head points back at the new node, and head moves onto the new node. 4. size goes up by one in both cases.

The DNode class is provided. Do not rename it and do not add public to it, because a Java source file may contain only one public class.

Do NOT write a main method.

Expected output

10 -> 20 -> 30 -> null
30 -> 20 -> 10 -> null
3

= newline. The output ends with a newline, so print one after the last line.

Hints4 available
Topics
Data Structures & AlgorithmsLinked Lists
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (sysout, psvm, fori)

Your output

Run your code to see the output here...

Test cases

Run your code to see test case results.