Read an integer n, then n integer keys. Insert them in order into an initially empty AVL tree (duplicates are ignored). Then print the pre-order traversal (keys separated by single spaces) and the height of the tree. The height of an empty tree is −1 and of a single node 0. If the tree is empty, print (empty) instead of the keys.
Because the rotations change the shape, the pre-order traversal shows whether you rebalanced correctly.
Input:
5 10 20 30 40 50
Output:
Pre-order: 20 10 40 30 50
Height: 2
Empty input (0):
Pre-order: (empty)
Height: -1