예제 #1
0
        private AVLTreeNode <T> FindWithParent(T value, out AVLTreeNode <T> parent)
        {
            AVLTreeNode <T> current = Head;

            parent = null;
            while (current != null)
            {
                int res = current.CompareTo(value);
                if (res > 0)
                {
                    parent  = current;
                    current = current.Left;
                }
                else if (res < 0)
                {
                    parent  = current;
                    current = current.Right;
                }
                else
                {
                    break;
                }
            }
            return(current);
        }
예제 #2
0
        //remove
        private AVLTreeNode <T> Find(T value)
        {
            AVLTreeNode <T> current = Head; // помещаем текущий элемент в корень дерева

            // Пока текщий узел на пустой
            while (current != null)
            {
                int result = current.CompareTo(value); // сравнение значения текущего элемента с искомым значением

                if (result > 0)
                {
                    // Если значение меньшне текущего - переход влево
                    current = current.Left;
                }
                else if (result < 0)
                {
                    // Если значение больше текщего - переход вправо
                    current = current.Right;
                }
                else
                {
                    // Элемент найден
                    break;
                }
            }
            return(current);
        }
        /// <summary>
        /// Finds and returns the first node containing the specified value.  If the value
        /// is not found, returns null.  Also returns the parent of the found node (or null)
        /// which is used in Remove.
        /// </summary>
        /// <param name="value">The value to search for</param>
        /// <param name="parent">The parent of the found node (or null)</param>
        /// <returns>The found node (or null)</returns>
        private AVLTreeNode <T> Find(T value)
        {
            // start from the head node
            AVLTreeNode <T> current = _head;

            // while we don't have a match
            while (current != null)
            {
                int result = current.CompareTo(value);
                // if current node's value is bigger than the value to be found
                if (result > 0)
                {
                    // go left
                    current = current.Left;
                }
                else if (result < 0)
                {
                    // go right
                    current = current.Right;
                }
                else
                {
                    // we have a match!
                    break;
                }
            }
            return(current);
        }
예제 #4
0
        private AVLTreeNode <T> Find(T value)
        {
            AVLTreeNode <T> current = Head;

            while (current != null)
            {
                int result = current.CompareTo(value);

                if (result > 0)
                {
                    current = current.Left;
                }
                else if (result < 0)
                {
                    current = current.Right;
                }
                else
                {
                    break;
                }
            }
            return(current);
        }