preOrder function