Beispiel #1
0
        private static void TestMergeSort()
        {
            Ch11_Sorting sortingMaster = new Ch11_Sorting();

            int[] arr = new int[] { 13, 3, 22, 21, 4, 32, 1, 9, 17 };
            sortingMaster.StartMergeSort(arr);
        }
Beispiel #2
0
        private static void TestBSearch()
        {
            Ch11_Sorting sorting = new Ch11_Sorting();

            int[] arr = new int[] { 2, 4, 5, 12, 39, 43, 45, 49, 62 };
            Console.WriteLine("{ 2,4, 5, 12, 39, 43, 45, 49, 62}");
            Console.WriteLine("Idx of 45 = {0}", sorting.BinarySearch(arr, 45));
            Console.WriteLine("Idx of 36 = {0}", sorting.BinarySearch(arr, 36));
            Console.WriteLine("Idx of 450 = {0}", sorting.BinarySearch(arr, 450));
            Console.WriteLine("Idx of 0 = {0}", sorting.BinarySearch(arr, 0));

            //Rotate arr
            arr = new int[] { 12, 39, 43, 45, 49, 62, 2, 4, 5 };
            Console.WriteLine("{  12, 39, 43, 45, 49, 62, 2, 4, 5}");
            Console.WriteLine("Idx of 45 = {0}", sorting.BSearchRotatedArray(arr, 45));
            Console.WriteLine("Idx of 36 = {0}", sorting.BSearchRotatedArray(arr, 36));
            Console.WriteLine("Idx of 450 = {0}", sorting.BSearchRotatedArray(arr, 450));
            Console.WriteLine("Idx of 0 = {0}", sorting.BSearchRotatedArray(arr, 0));
            Console.WriteLine("Idx of 2 = {0}", sorting.BSearchRotatedArray(arr, 2));
            Console.WriteLine("Idx of 62 = {0}", sorting.BSearchRotatedArray(arr, 62));
        }