transform tree-like array into list-like array