Ejemplo n.º 1
0
        private Node PlaceInRoot(int nodeValue, Node root)
        {
            if (root == null || root.HasNoChild())
            {
                return(null);
            }

            var parent = GetParent(nodeValue);
            var node   = FindNode(nodeValue);

            while (parent != null && node != null && !node.HasDirectChild(root))
            {
                if (node.Value < parent.Value)
                {
                    node = RightRotation(parent.Value);
                }
                else
                {
                    node = LeftRotation(parent.Value);
                }

                parent = GetParent(node.Value);
                node   = FindNode(node.Value);
            }

            return(node);
        }