Question: 9 . 3 1 LAB: Iterable 2 - 3 - 4 tree In this lab, the Tree 2 3 4 class is extended to support
LAB: Iterable tree
In this lab, the Tree class is extended to support iteration with an enhanced for loop. Such support is provided via the implementation of an iterator that can iterate through the tree's keys in ascending order.
An iterator is an object that maintains a reference to a specific element in a collection and can move to the next element. Ex: A Tree iterator references the tree's minimum key upon construction. The iterator can then move to the second to minimum key, then the third to minimum, and so on Eventually the iterator moves to the last key and can move no further.
Overview of Iterable and Iterator in Java
Enhanced for loops work on any class that implements the Iterable interface. Tree stores a collection of integer keys, so the Tree class implements Iterable
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
