public void postOrderTraverse(BiTreeNode node) { if (null != node) { postOrderTraverse(node.getLeftchild()); postOrderTraverse(node.getRightchild()); if (null != node.getData()) { node.getData().show(); } } }
public static void inOrderTraverse(BiTreeNode node) { if (null != node) { inOrderTraverse(node.getLeftchild()); if (null != node.getData()) { node.getData().show(); } inOrderTraverse(node.getRightchild()); } }
public BiTreeNode preOrderCreateBiTree(String init, BiTreeNode t) { if ("#".equalsIgnoreCase(init.substring(0, 1))) { t = null; } else { BiTreeNodeData d = new BiTreeNodeData(init.substring(0, 1)); t = new BiTreeNode(); t.setData(d); t.setLeftchild(preOrderCreateBiTree(init.substring(1), t.getLeftchild())); t.setRightchild(preOrderCreateBiTree(init.substring(1), t.getRightchild())); } return t; }
/* Give a binary search tree and a number, inserts a new node with the given number in the correct place in the tree. Returns the new root pointer which the caller should then use (the standard trick to avoid using reference parameters). */ public static BiTreeNode insert(BiTreeNode node, int data) { if (null == node) { return newNode(data); } else { if (data <= node.getData().getIdata()) { node.setLeftchild(insert(node.getLeftchild(), data)); } else { node.setRightchild(insert(node.getRightchild(), data)); } // return the (unchanged) node pointer return node; } }