コード例 #1
0
 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);
             }
         }
     }
 }
コード例 #2
0
 public NodeBST(int key)
 {
     this.parent = null;
     this.key    = key;
     this.left   = null;
     this.right  = null;
 }
コード例 #3
0
        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);
        }
コード例 #4
0
 public int GetHeight(NodeBST node)
 {
     if (node == null)
     {
         return(-1);
     }
     else
     {
         return(node.height);
     }
 }
コード例 #5
0
        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);
        }
コード例 #6
0
 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());
     }
 }