Question: IN JAVA class ListItem { String data; ListItem next; // To point to next node in list. ListItem prev; // To point to the previous
IN JAVA class ListItem { String data; ListItem next; // To point to next node in list. ListItem prev; // To point to the previous node in the list. } public class DoublyLinkedList2 { // Instance variables. ListItem front = null; ListItem rear = null; int numItems = 0; public void add (String s) { if (front == null) { // Similar to singly-linked list, except for setting rear.prev front = new ListItem (); front.data = s; rear = front; rear.next = null; rear.prev = null; // Must set this correctly. } else { // Make new ListItem and set its fields correctly. ListItem nextOne = new ListItem (); nextOne.data = s; nextOne.next = null; nextOne.prev = rear; // Adjust the next pointer of the current last one, and adjust rear itself. rear.next = nextOne; rear = nextOne; } numItems ++; } public int size () { return numItems; } public String get (int i) { if (i >= numItems) { return null; } int count = 0; ListItem listPtr = front; while (count
public class DoublyLinkedListExample2 { public static void main (String[] argv) { DoublyLinkedList2 favoriteShows = new DoublyLinkedList2(); favoriteShows.add ("Crocodile Hunter"); favoriteShows.add ("Jon Stewart"); favoriteShows.add ("Evening at the Improv"); favoriteShows.add ("Monty Python"); favoriteShows.add ("SNL"); favoriteShows.reversePrint (); } }

Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
