Implemented to_array: convert tree to an ordered Array