Traverse the whole tree, insert every node value into an array and then sort the array.
Is there any better way to do it?
Anonymous
7 Nov 2016
Is it a binary search tree? Does the tree handle duplicates?
Can't we do an in-order traversal of the tree and store the values of the nodes we visit in the array? I think using an arraylist would be more helpful, since if we use an array we have to traverse through the binary tree first to get the size to initiate the array.
Anonymous
26 Feb 2017
The answer depends on whether or not the binary tree is a BST. If not, you may as well just copy all of the nodes over to an array and sort in place.