Sorting the elements of binary search tree with preorder traversal