Write a parameterized class definition for a doubly linked list that has a parameter for the type of data stored in a node. Make the node class an inner class. Choosing which methods to define is part of this project. Also, write a program to thoroughly test your class definition.

This program is based on code from Listing 12.9. The solution given here includes support for iteration, both forward and reverse. Both forward and reverse iteration use the moreToIterate method, but backward iteration uses the resetIterationReverse rather than resetIteration. The ListNode class includes a previous instance variable which makes the previous variable in the outer class unnecessary. To make reverse iteration (especially resetIterationReverse) easier to write, there is a reference to the tail of the list as well as to the head of the list. An additional method, findInList, looks for an element in the list and sets current to point to that element if it is found. If it is not found, current is set to null. The method showListState is for testing and debugging purposes and prints the head of the list, the current element, the tail, and the number of elements in the list.


See the code in DoublyLinkedList.java, and DoublyLinkedListDemo.java.

Computer Science & Information Technology

You might also like to view...

Which of the following does not declare a 2-by-2 array and set all four of its elements to 0?

a. array, 2> b; b[0][0] = b[0][1] = b[1][0] = b[1][1] = 0; b. array, 2> b = {0}; c. array, 2> b; for (auto const &row : b) { for (auto &element : row) { element = 0; } } d. All of the above initialize all four of the array elements to

Computer Science & Information Technology

The latest release of Linux kernel 3.3 contains more than 15 million lines of source code.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

What is a markup language? Give two examples and describe how they are useful

What will be an ideal response?

Computer Science & Information Technology

Which characteristic of sound refers to its loudness?

A. Wavelength B. Frequency C. Amplitude D. Timbre

Computer Science & Information Technology