コード例 #1
0
        public bool Sil(int deger)
        {
            BinaryTreeNode current = root;
            BinaryTreeNode parent  = root;
            bool           issol   = true;

            while (current.data.Id != deger)
            {
                parent = current;
                if (deger < current.data.Id)
                {
                    issol   = true;
                    current = current.left;
                }
                else
                {
                    issol   = false;
                    current = current.right;
                }
                if (current == null)
                {
                    return(false);
                }
            }

            if (current.left == null && current.left == null)
            {
                if (current == root)
                {
                    root = null;
                }
                else if (issol)
                {
                    parent.left.data = null;
                }
                else
                {
                    parent.right.data = null;
                }
            }
            else if (current.right == null)
            {
                if (current == root)
                {
                    root = current.left;
                }
                else if (issol)
                {
                    parent.left = current.left;
                }
                else
                {
                    parent.right = current.right;
                }
            }
            else if (current.left == null)
            {
                if (current == root)
                {
                    root = current.right;
                }
                else if (issol)
                {
                    parent.left = current.right;
                }
                else
                {
                    parent.right = current.right;
                }
            }
            //DURUM 3: İKİ ÇOCUKLU DÜĞÜM
            else
            {
                BinaryTreeNode successor = Successor(current);
                if (current == root)
                {
                    root = successor;
                }
                else if (issol)
                {
                    parent.left = successor;
                }
                else
                {
                    parent.right = successor;
                }
                successor.left = current.left;
            }
            return(true);
        }
コード例 #2
0
 private void Visit(BinaryTreeNode node)
 {
     nodes.Add(node.data);
 }
コード例 #3
0
 public BinaryTree(BinaryTreeNode _root)
 {
     nodes     = new List <Hotel>();
     this.root = _root;
 }