Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Why does the constructor for theLinkedListIteratorin Ch. 17.2 have package (default) visibility instead of public? package weiss.nonstandard; // LinkedListIterator class; maintains current position // //

Why does the constructor for theLinkedListIteratorin Ch. 17.2 have package (default) visibility instead of public?

package weiss.nonstandard;

// LinkedListIterator class; maintains "current position" // // CONSTRUCTION: Package visible only, with a ListNode // // ******************PUBLIC OPERATIONS********************* // void advance( ) --> Advance // boolean isValid( ) --> True if at valid position in list // AnyType retrieve --> Return item in current position

/** * Linked list implementation of the list iterator * using a header node. * @author Mark Allen Weiss * @see LinkedList */ public class LinkedListIterator { /** * Construct the list iterator * @param theNode any node in the linked list. */ LinkedListIterator( ListNode theNode ) { current = theNode; }

/** * Test if the current position is a valid position in the list. * @return true if the current position is valid. */ public boolean isValid( ) { return current != null; }

/** * Return the item stored in the current position. * @return the stored item or null if the current position * is not in the list. */ public AnyType retrieve( ) { return isValid( ) ? current.element : null; }

/** * Advance the current position to the next node in the list. * If the current position is null, then do nothing. */ public void advance( ) { if( isValid( ) ) current = current.next; }

ListNode current; // Current position }

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

Mobile Usability

Authors: Jakob Nielsen, Raluca Budiu

1st Edition

0133122131, 9780133122138

More Books

Students also viewed these Programming questions