Beispiel #1
0
        /// <summary>
        ///Search for value under current node incusive.
        /// </summary>
        /// <param name="data">Sought value.</param>
        /// <returns>Return list of nodes which satisfy the query</returns>
        internal List <TreeNode <T> > FindUnderNode(T data, IComparer <T> comparer)
        {
            var tempList = new List <TreeNode <T> >();

            if (BinaryTree <T> .CompareValues(data, Value, comparer) == 0)
            {
                tempList.Add(this);
                if (RightNode != null)
                {
                    tempList.AddRange(RightNode.FindUnderNode(data, comparer));
                }
                return(tempList);
            }
            else if (BinaryTree <T> .CompareValues(data, Value, comparer) < 0 && LeftNode != null)
            {
                tempList.AddRange(LeftNode.FindUnderNode(data, comparer));
                return(tempList);
            }
            else if (BinaryTree <T> .CompareValues(data, Value, comparer) > 0 && RightNode != null)
            {
                tempList.AddRange(RightNode.FindUnderNode(data, comparer));
                return(tempList);
            }
            else
            {
                return(tempList);
            }
        }