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 inOrder(BinaryNode currentRoot) { if (currentRoot != null) { inOrder(currentRoot.getLeftChild()); Console.WriteLine(currentRoot.getData() + " "); inOrder(currentRoot.getRightChild()); } }
private void add(int data, BinaryNode root) { if (data < root.getData()) { //validacion por la izquierada insertion(data, root, 0); } else { //validacion por la derecha insertion(data, root, 1); } }
private BinaryNode search(int data, BinaryNode currentRoot) { if (currentRoot == null) { return(null); } if (data == currentRoot.getData()) { return(currentRoot); } parent = currentRoot; if (data < currentRoot.getData()) { //if false the position is left position = true; return(search(data, currentRoot.getLeftChild())); } else { //if true the the position is right position = false; return(search(data, currentRoot.getRightChild())); } }
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); } }