Iterators Flashcards
1
Q
What is an iterator?
A
an ADT that allows us to acess one by one the data items in a collection
2
Q
What 3 operations does an iterator provide?
A
next
hasNext
remove
3
Q
What does next() return?
A
returns the next data item in the collection. Error if the data item does not exist
4
Q
What does hasNext() return?
A
Returns true if there are more data items that have not been accessed; false otherwise
5
Q
What does the remove() return?
A
Removes the last data iem returned by the next operation
6
Q
What does an Array implementation of iterator contain?
A
- Stores the data items in an array
- Fix first data item of the list at index 0
- Variable count indicates the number of data items(size)
- Variable current indicates the current position of the iteration