private void deleteNode(int data, BinaryNode currentRoot) { BinaryNode tempNode = search(data); if (tempNode.isLeaf()) { if (position) { parent.setLeftChild(null); } else { parent.setRightChild(null); } } else if (tempNode.hasOneChild()) { if (tempNode.getchildPosition()) { parent.setLeftChild(tempNode.getLeftChild()); } else { parent.setRightChild(tempNode.getRightChild()); } } else { BinaryNode min = getMinor(tempNode.getRightChild()); deleteNode(min.getData()); tempNode.setData(min.getData()); } }
private void countLeafs(BinaryNode currentRoot) { if (currentRoot != null) { countLeafs(currentRoot.getLeftChild()); countLeafs(currentRoot.getRightChild()); if (currentRoot.isLeaf()) { leafs++; } } }
public void preOrder() { if (root == null) { Console.WriteLine("My man, the tree is empty"); } if (root.isLeaf()) { Console.WriteLine("My man, the only existing node is the root: " + root.getData()); } else { preOrder(root); } }