Ejemplo n.º 1
0
        public void inOrderDesc(AVLNode node, List <int> result)
        {
            if (node != null)
            {
                inOrderDesc(node.getRight(), result);

                result.Add(node.getData());

                inOrderDesc(node.getLeft(), result);
            }
        }
Ejemplo n.º 2
0
        public int getMin()
        {
            AVLNode current = root;

            if (current == null)
            {
                return(Int32.MinValue);
            }

            while (current.getLeft() != null)
            {
                current = current.getLeft();
            }

            return(current.getData());
        }
Ejemplo n.º 3
0
        public int getMax()
        {
            AVLNode current = root;

            if (current == null)
            {
                return(Int32.MaxValue);
            }

            while (current.getRight() != null)
            {
                current = current.getRight();
            }

            return(current.getData());
        }
Ejemplo n.º 4
0
        public AVLNode deleteR(AVLNode root, int value)
        {
            if (root == null)
            {
                return(root);
            }

            AVLNode toCompare = new AVLNode(value, null, null);

            if (toCompare.compareTo(root) < 0)
            {
                root.setLeft(deleteR(root.getLeft(), value));
            }
            else if (toCompare.compareTo(root) > 0)
            {
                root.setRight(deleteR(root.getRight(), value));
            }
            else
            {
                if (root.getLeft() == null || root.getRight() == null)
                {
                    AVLNode temp = null;

                    if (temp == root.getLeft())
                    {
                        temp = root.getRight();
                    }
                    else
                    {
                        temp = root.getLeft();
                    }



                    if (temp == null)
                    {
                        temp = root;

                        root = null;
                    }
                    else
                    {
                        root = temp;
                    }
                }
                else
                {
                    AVLNode temp = minValueNode(root.getRight());

                    root.setData(temp.getData());

                    root.setRight(deleteR(root.getRight(), temp.getData()));
                }
            }



            if (root == null)
            {
                return(root);
            }

            root.setHeight(Math.Max(height(root.getLeft()), height(root.getRight())) + 1);

            int balanceFactor = BalanceFactor(root);

            if (balanceFactor < -1)
            {
                if (BalanceFactor(root.getRight()) > 0)
                {
                    root.setRight(rotateRight(root.getRight()));

                    return(rotateLeft(root));
                }
                else
                {
                    return(rotateLeft(root));
                }
            }
            else if (balanceFactor > 1)
            {
                if (BalanceFactor(root.getLeft()) < 0)
                {
                    root.setLeft(rotateLeft(root.getLeft()));

                    return(rotateRight(root));
                }
                else
                {
                    return(rotateRight(root));
                }
            }

            return(root);
        }
 public int compareTo(AVLNode o)
 {
     return(this.data.CompareTo(o.getData()));
 }