Java exercise in traversing a tree using breadth-first algorithm