iterator

open operator override fun iterator(): Iterator<TreeNode<T>>

Tree is iterated by using `Pre-order Traversal Algorithm"

  1. Check if the current node is empty or null.

  2. Display the data part of the root (or current node).

  3. Traverse the left subtree by recursively calling the pre-order function.

  4. Traverse the right subtree by recursively calling the pre-order function.

                     colors
/ | \
/ | \
a b c
/ \ / | \
a1 a2 c1 c2 c3
/ / | \
a11 a21 a22 a23

Output: colors a a1 a11 a2 a21 a22 a23 b c c1 c2 c3