English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Write a method in the Tree class to dump (Parse InOrder) the contents to a textfile "inorder.txt".

private void inorderHelper( TreeNode node ) {
if ( node == null )
return;

//traverse left subtree
inorderHelper( node.leftNode );
//output node data
System.out.print( node.data + " " );
//traverse right subtree
inorderHelper( node.rightNode );
}//inorderHelper()

// begin postorder traversal
public void postorderTraversal() {
postorderHelper( root );
}

2006-12-19 15:56:45 · 1 answers · asked by Anonymous in Computers & Internet Programming & Design

1 answers

I think the code should be
private void inorderHelper( TreeNode node ) {
if ( node == null ) {
return;
}
if(node.left != null) {
inorderHelper( node.leftNode );
}
System.out.print( node.data + " " );
if(node.right != null) {
inorderHelper( node.rightNode );
}
}

2006-12-19 16:34:31 · answer #1 · answered by Neil 5 · 0 0

fedest.com, questions and answers