This is an extension to Java Tree structure interview questions and coding questions — Part 3 where recursion was used for FlattenTree interface. Let’s use iteration here. Step 1: The FlattenTree interface.
|
1 2 3 4 5 6 7 |
package com.mycompany.flatten; public interface FlattenTree<T> { void flatten(Tree<T> tree); } |
Step 2: The iterative implementation IterativeFlattenTree. This uses a LIFO stack…