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