finished the preOrder traverse function