Kod: Zaznacz cały
package bst;
public class BST {
private Node root;
private class TreeException extends Throwable {
TreeException() {}
TreeException(String msg) { super(msg); }
}
private class Node {
int key;
Node left;
Node right;
Node parent = null;
private int value;
Node(int key) {
this.key = key;
}
}
public void add(int newValue){
if(root == null)
root = new Node(newValue);
else {
Node actual = root;
Node parent = null;
while(actual != null) {
parent = actual;
actual = (actual.newValue > newValue) ? actual.left : actual.right;
}
if(parent.newValue > newValue) {
parent.left = new Node(newValue);
parent.left.parent = parent;
}
else {
parent.right = new Node(newvalue);
parent.right.parent = parent;
}
}
}
}
public boolean remore(int value){
}
public Node search(int value){
}
print LKP(){
LKP(root);
}
LKP(Node node){
LKP (node.get
System.out.print(node.getValue));
LKP (node.getRight());
}
public static void main(String[] args) {
}
}