Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 (); } }

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Put Your Data To Work 52 Tips And Techniques For Effectively Managing Your Database

Authors: Wes Trochlil

1st Edition

0880343079, 978-0880343077

More Books

Students also viewed these Databases questions