implemented second version of the get_next_node_preorder algorithm