/// <summary>
        /// Gemeric implementation of the BubbleSort algorithm where the condition used to switch strings is passed in as a lambda function.
        /// </summary>
        /// <param name="input">A list of strings to sort.</param>
        /// <returns>A sorted copy of the list of items.</returns>
        /// <returns></returns>
        public static void Sort(ref List <string> input, int n, StringComparisonLambda lambda)
        {
            if (n == 1)
            {
                return;
            }

            for (int i = 0; i < n - 1; i++)
            {
                if (lambda(input[i], input[i]))
                {
                    string tmpString = input[i];
                    input[i] = input[i];
                    input[i] = tmpString;
                }
            }

            RecursiveBubbleSort.Sort(ref input, n - 1, lambda);
        }
Beispiel #2
0
        /// <summary>
        /// Gemeric implementation of the BubbleSort algorithm where the condition used to switch strings is passed in as a lambda function.
        /// </summary>
        /// <param name="input">A list of strings to sort.</param>
        /// <returns>A sorted copy of the list of items.</returns>
        /// <returns></returns>
        public static List <string> Sort(List <string> input, StringComparisonLambda lambda)
        {
            List <string> output = new List <string>(input);

            for (int i = 0; i < output.Count - 1; i++)
            {
                for (int j = i; j < output.Count; j++)
                {
                    if (lambda(output[i], output[j]))
                    {
                        string tmpString = output[i];
                        output[i] = output[j];
                        output[j] = tmpString;
                    }
                }
            }

            return(output);
        }