Problem

Consider the definition of the add method that adds an entry to a list at a given position...

Consider the definition of the add method that adds an entry to a list at a given position and appears in Segment 14.11. Replace the statements that execute in case 1 with the following ones:

if (isEmpty() || (newPosition == 1)) // case 1{  firstNode = newNode;  newNode.next = firstNode;}

a. What is displayed by the following statements in a client of the modified LList?


ListInterface myList = new LList();myList.add(1, "30");myList.add(2, "40");myList.add(3, "50");myList.add(1, "10");myList.add(5, "60");myList.add(2, "20");int numberOfEntries = myList.getLength();for (int position = 1; position <= numberOfEntries; position++)System.out.print(myList.getEntry(position) + " ");

b. What methods, if any, in LList could be affected by the change to the method add when they execute? Why?

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 14
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT