static void Main()
        {
            int[] array = new int[] { 2, 4, 1, 6, 10 };
            int[] sortedArray = (int[])array.BubbleSort(new MyIntComparer());
            foreach (var item in sortedArray)
                Console.WriteLine(item);
            Console.WriteLine();

            List<int> list = new List<int> { 5, 2, 1, 72, 12, 34, 11 };
            list.SelectionSort(new MyIntComparer());
            list.ForEach(Console.WriteLine);
            Console.WriteLine();

            string str1 = "abc";
            string str2 = null;
            var stringComparer = new StringLengthComparer();
            if (stringComparer.Compare(str1, str2) > 0)
                Console.WriteLine("The first string is longer than the second string.");
            else if (stringComparer.Compare(str1, str2) == 0)
                Console.WriteLine("The string are equal.");
            else
                Console.WriteLine("The first string is shorter than the second string");

            int? first = 12;
            int? second = 7;
            OddEvenComparer comparer = new OddEvenComparer();
            Console.WriteLine(comparer.Compare(first, second));
            Console.WriteLine();

            var list2 = new List<int>() { 1, 6, 12, 123, 343, 564, 1243 };
            Console.WriteLine(list2.BSearch(1243, new MyIntComparer()));
        }
Пример #2
0
        static void Main(string[] args)
        {
            List<int> listOfIntegers = new List<int>() { 4, 23, 2, 15, 11, 64, 7, 3, 1 };
            List<int?> listOfNullableIntegers = new List<int?>() { 4, null, 2, 15, null, 64, 7, 11, 66, 5, 8 };
            List<string> listOfStrings = new List<string> {"asd", "asdf", "mnogodulugstring" , "s", "ae", string.Empty, "asdec"};

            listOfIntegers.BubbleSort();
            foreach (var item in listOfIntegers)
            {
                Console.Write("{0} ", item);
            }

            Console.WriteLine();

            listOfNullableIntegers.SelectionSort(new OddEvenComparer());
            foreach (var item in listOfNullableIntegers)
            {
                Console.Write("{0} ", item);
            }

            Console.WriteLine();

            listOfStrings.SelectionSort(new StringLengthComparer());
            foreach (var item in listOfStrings)
            {
                Console.Write("{0} ", item);
            }

            Console.WriteLine();

            Console.WriteLine(listOfIntegers.BSearch(1)); // 0

            List<int> listOfIntegersQS = new List<int>() { 4, 5, 1, 3, 2 };
            List<int> listOfIntegersMS = new List<int>() { 1, 7, 13, 3, 9, 5, 11 };

            listOfIntegersQS.QuickSort();
            foreach (var item in listOfIntegersQS)
            {
                Console.Write("{0} ", item);
            }

            Console.WriteLine();

            listOfIntegersMS.MergeSort();
            foreach (var item in listOfIntegersMS)
            {
                Console.Write("{0} ", item);
            }

            Console.WriteLine();
        }