Question: class ListItem { String data; ListItem next; } public class ListWithLinks2 { // Instance variables. ListItem front = null; ListItem rear = null; // To
class ListItem { String data; ListItem next; } public class ListWithLinks2 { // Instance variables. ListItem front = null; ListItem rear = null; // To keep track of the size. int numItems = 0; public void add (String s) { if (front == null) { // The special case of an empty list needs to be handled differently. front = new ListItem (); front.data = s; rear = front; rear.next = null; } else { // Just like before: ListItem nextOne = new ListItem (); nextOne.data = s; rear.next = nextOne; rear = nextOne; } numItems ++; } public int size () { return numItems; } public String get (int i) { if (i >= numItems) { return null; } // Otherwise, count up to the i-th item. int count = 0; ListItem listPtr = front; while (count
public class ListWithLinksExample2 { public static void main (String[] argv) { ListWithLinks2 favoriteShows = new ListWithLinks2(); favoriteShows.add ("Yes minister"); favoriteShows.add ("Seinfeld"); favoriteShows.add ("Cheers"); favoriteShows.add ("Frasier"); favoriteShows.add ("Simpsons"); favoriteShows.printList (); } }

va and List ple2,java and implement the printti at) method in LiatwithLinks2 to print out the list. The code in ListwithlinkaExample2 calls this method 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
