- Iterators For The Adt List Test Bank Chapter 13 - Data Structures with Java 5e Complete Test Bank by Frank M. Carrano. DOCX document preview.
Chapter 13 - Iterators for the ADT List
True/False (11)
- A separate class iterator is usually preferable to an inner class iterator.
- You invoke the methods of the inner class iterator and the separate class iterator differently.
- The definition of the class SeparateIterator is dependent on which implementation of a list you choose.
- The class SeparateIterator cannot access the private data fields of the class that implements the list.
- A separate class iterator can take longer to execute than an inner class iterator.
- If you use a separate class iterator, you cannot have multiple and distinct iterations of a list exist simultaneously.
- When a list iterator object is distinct from the list ADT you can have multiple iterations in progress at the same time.
- An iterator that is implemented as an inner class of a list ADT has direct access to the ADT’s data fields.
- A class that defines an inner class iterator should implement the interface Iterable.
- An iterator does not typically allow the removal of items during a traversal.
- An inner class iterator typically executes faster than a separate class iterator because it accesses the list ADT’s data directly.
Short Answer (5)
- Using the LinkedListWithInterator class, create an iterator named printIterator. The objects in the list object are type String. The list object is called reports.
- Using the LinkedListWithInterator class, create an iterator named rosterIterator. The objects in the list object are type Student. The list object is called collegeClass.
Iterator<Student> rosterIterator = collegeClass.getIterator();
- Why is it better to implement the iterator as a class, whether separate or inner, than simply adding the iterator functionality as additional ADT operations?
- Why is the inner class iterator faster than the separate class iterator?
- Explain why the set method in the ListIteratorForArrayList inner class assigns values to array elements rather than calling the replace method in the outer list class.
Multiple Choice (29) WARNING: CORRECT ANSWERS ARE IN THE SAME POSITION AND TAGGED WITH . YOU SHOULD RANDOMIZE THE LOCATION OF THE CORRECT ANSWERS IN YOUR EXAM.
- Which method does the interface Iterator specify?
- hasNext
- next
- remove
- all of the above
- A(n) ____ is an object that enables you to traverse a list.
- iterator
- traversal object
- list counter
- walker
- A class that is public and separate from the class that implements the ADT in question is called a(n)
- separate class iterator
- inner class iterator
- outer class iterator
- public iterator
- A class that is a private inner class of the class that implements the ADT in question is called a(n)
- inner class iterator
- outer class iterator
- separate class iterator
- private iterator
- The constructor in the SeparateIterator class
- initializes the iterator so it begins at the first entry in the list
- connects the iterator to the list in question
- both a & b
- none of the above
- In the SeparateIterator class, how does the method next behave when iteration has ended?
- It throws an exception.
- It returns null.
- It returns false.
- It returns the last element in the list
- What does the hasNext method return when the list is empty?
- false
- true
- null
- 0
- If iteration has ended, the next method
- throws an exception
- returns false
- returns null
- returns 0
- If iteration has ended, the next method
- throws a NoSuchElementException
- throws an EndOfIterationException
- throws a IllegalStateException
- none of the above
- If the remove method has been called since the last call to the next method
- an IllegalStateException is thrown
- the last entry returned from the next method is removed
- the method returns false
- the method returns null
- The _____ deletes the most recent entry returned from the next method from the list.
- remove
- delete
- deleteNext
- clear
- In the SeparateIterator class, when the data field wasNextCalled is true it means
- that a call to remove is safe
- that the list is empty
- that iteration has stopped
- all of the above
- In the SeparateIterator class, when the data field wasNextCalled is false it means
- a subsequent call to remove requires another call to next
- the iterator has ended
- the list is empty
- all of the above
- After a call to remove, the nextPosition data field should be
- decremented
- incremented
- left unaltered
- set to 0
- A separate class iterator is a good choice when
- an ADT’s implementation does not have an iterator and cannot be altered
- an ADT’s implementation does not have an iterator and can be altered
- an inner class iterator is too difficult to implement
- none of the above
- Separate class iterators access the list’s data fields
- via ADT operations
- directly
- both a & b
- none of the above
- Inner class iterators can access the list’s data fields
- directly if there is no naming conflict
- directly regardless of a naming conflict
- through special function calls
- through the list interface
- A class that defines an inner class iterator should implement the
- Iterator interface
- ListIterator interface
- Iteration interface
- none of the above
- In the IteratorForLinkedList class, what happens when the next method is called but iteration has ended?
- It throws a NoSuchElementException.
- It throw an IteratorEndedException.
- It returns false.
- It returns null.
- In the IteratorForLinkedList class, the hasNext method determines iteration has ended by
- check if the nextNode variable is null
- setting a special boolean flag to true
- setting a special boolean flag to false
- checking if the node count is zero
- In the IteratorForLinkedList class, what happens when the remove method is called?
- An UnsupportedOperationException is thrown.
- It returns true.
- It returns false.
- It returns null.
- In the IteratorForLinkedList class, the remove method
- is not supported
- removes the node at the specified position
- removes the first node in the list
- removes the last node in the list
- In the IteratorForArrayList class, the hasNext method determines iteration has ended by
- comparing the nextIndex to the numberOfEntries
- IteratorForLinkedList
- setting a special boolean flag to true
- setting a special boolean flag to false
- In the IteratorForArrayList class,when the hasNext method returns false, the next method
- throws an exception
- returns false
- returns true
- returns null
- When an ADT has too many operations, it is commonly known as
- interface bloat
- operation overload
- method overload
- interface exhaustion
- In the ListIteratorForArrayList class, the remove method throws an IllegalStateExeption when
- the next method was not called
- the previous method was not called
- remove has been called since the last call to next or previous
- all of the above
- In the IteratorForArrayList class, the set method throws an IllegalStateExeption when
- the next method was not called
- the previous method was not called
- add has been called since the last call to next or previous
- all of the above
- In the IteratorForArrayList class, the isRemoveOrSetLegal variable is
- set to false by the constructor
- set to true by next
- set to false by add
- all of the above
- In the IteratorForArrayList class, the isRemoveOrSetLegal variable is
- set to false by the constructor
- set to true by previous
- set to false by remove
- all of the above
Document Information
Connected Book
Data Structures with Java 5e Complete Test Bank
By Frank M. Carrano
Test Bank
General
View Product →
Explore recommendations drawn directly from what you're reading
Quick Navigation
Benefits
Immediately available after payment
Answers are available after payment
ZIP file includes all related files
Files are in Word format (DOCX)
Check the description to see the contents of each ZIP file
We do not share your information with any third party