public void Insert(NodeBST node) { if (node == null) { return; } else { if (this.key > node.key) { if (this.left == null) { this.left = node; node.parent = this; } else { this.left.Insert(node); } } else { if (this.right == null) { this.right = node; node.parent = this; } else { this.right.Insert(node); } } } }
public NodeBST(int key) { this.parent = null; this.key = key; this.left = null; this.right = null; }
public NodeBST Find_Min() { //Tree'de yer alan en küçük elemanı gönderir. NodeBST current = this; while (current != null) { current = current.left; } return(current); }
public int GetHeight(NodeBST node) { if (node == null) { return(-1); } else { return(node.height); } }
public NodeBST Next_Larger() { //Şu ankinden bir büyük sırada olan node'u döndürür. NodeBST current = this; if (current.right != null) { return(current.right.Find_Min()); } while (current.parent != null && current == current.parent.right) { current = current.parent; } return(current.parent); }
public NodeBST Delete() { if (this.left == null || this.right == null) { if (this == this.parent.left) { if (this.left == null) { this.parent.left = this.right; } else { this.parent.left = this.left; } if (this.parent.left != null) { this.parent.left.parent = this.parent; } } else { if (this.left == null) { this.parent.right = this.right; } else { this.parent.right = this.left; } if (this.parent.right != null) { this.parent.right.parent = this.parent; } } return(this); } else { NodeBST s = this.Next_Larger(); s.left = this.left; s.right = this.right; s.key = this.key; s.parent = this.parent; return(s.Delete()); } }