← Back to Data Structures & Algorithms
Question 449
Walk a Doubly Linked List Both Ways
Walk a Doubly Linked List Both Ways
Every DNode carries a prev as well as a next, so the same chain can be read from either end.addFirst()andaddLast()already keep both links wired. Requirements: 1.printForward()returns one string built from head, following next. 2.printBackward()returns one string built from tail, following prev. 3. Both join the values with an arrow and finish with the word null, so an empty list gives just that word. 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 — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
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.