}
Node
while (node.right != null) {
node = node.right;
}
return node;
}
public Node
if (root != null) {
return max(root);
} else {
return null;
}
}
public Node
if (node == null) {
throw new IllegalArgumentException("node can not be null");
}
if (node.right != null) {
return min(node.right);
}
Node
Node
while (parent != null && processNode == parent.right) {
processNode = parent;
parent = processNode.parent;
}
return parent;
}
public Node
if (node == null) {
throw new IllegalArgumentException("node can not be null");
}
if (node.left != null) {
return max(node.left);
}
Node
Node
while (parent != null && processNode == parent.left) {
processNode = parent;
parent = processNode.parent;
}
return parent;
}
public void print() {
print(root);
}
public void print(Node
if (node == null) {
return;
}
print(node.left);
System.out.print(" " + node.value.toString() + " ");
print(node.right);
}
public static class Node
private Node
private Node
private Node
private T value;
public Node(Node
this.parent = parent;
this.value = value;
}
public Node
return parent;
}
public void setParent(Node
this.parent = parent;
}
public Node
return left;
}
public void setLeft(Node
this.left = left;
}
public Node
return right;
}
public void setRight(Node
this.right = right;
}
public T getValue() {
return value;
}
public void setValue(T value) {
this.value = value;
}
}
public static void main(String[] args) {
BinaryTree
tree.insert("Hello");
tree.insert("World");
tree.insert("Money");
tree.print();
System.out.println();
Node
tree.print(moneyNode);
System.out.println();
tree.insert("Like");
tree.print(moneyNode);
System.out.println();
tree.delete(moneyNode);
tree.print();
System.out.println();
}
}