method preorder in treeTraversals