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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What 3 operations does an iterator provide?

A

next
hasNext
remove

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does next() return?

A

returns the next data item in the collection. Error if the data item does not exist

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does hasNext() return?

A

Returns true if there are more data items that have not been accessed; false otherwise

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does the remove() return?

A

Removes the last data iem returned by the next operation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does an Array implementation of iterator contain?

A
  1. Stores the data items in an array
  2. Fix first data item of the list at index 0
  3. Variable count indicates the number of data items(size)
  4. Variable current indicates the current position of the iteration
How well did you know this?
1
Not at all
2
3
4
5
Perfectly