Beispiel #1
0
        /// <summary>
        /// Finds a specific item in the tree
        /// </summary>
        /// <param name="value">The value to find</param>
        /// <returns>The AVLTreeNode if found, otherwise, null</returns>
        private AVLTreeNode <T> Find(T value)
        {
            AVLTreeNode <T> current = Head;

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

                if (result > 0)
                {
                    // If the value is less than current, go left
                    current = current.Left;
                }
                else if (result < 0)
                {
                    // If the value is greater than current, go right
                    current = current.Right;
                }
                else
                {
                    // Found it
                    break;
                }
            }

            return(current);
        }
Beispiel #2
0
        /// <summary>
        /// Finds and returns the first node containing the specified value.  If the value
        /// is not found, returns null.
        /// </summary>
        /// <param name="value">The value to search for</param>
        /// <returns>The found node (or null)</returns>
        private AVLTreeNode <T> Find(T value)
        {
            // Now, try to find data in the tree
            AVLTreeNode <T> current = Head;

            // while we don't have a match
            while (current != null)
            {
                int result = current.CompareTo(value);

                if (result > 0)
                {
                    // if the value is less than current, go left.
                    current = current.Left;
                }
                else if (result < 0)
                {
                    // if the value is more than current, go right.
                    current = current.Right;
                }
                else
                {
                    // we have a match!
                    break;
                }
            }

            return(current);
        }