Пример #1
0
    // No Input Validations
    public static int BinarySearch <T>(T[] arr, T value) where T : IComparable <T>
    {
        int startIndex = 0;
        int endIndex   = arr.Length - 1;
        int result     = AlgorithmsAssertions.BinarySearch(arr, value, startIndex, endIndex);

        return(result);
    }
Пример #2
0
    // No Input Validations
    public static void SelectionSort <T>(T[] arr) where T : IComparable <T>
    {
        int arrayLength = arr.Length - 1;

        for (int index = 0; index < arrayLength; index++)
        {
            int minElementIndex = AlgorithmsAssertions.FindMinElementIndex(arr, index, arrayLength);
            AlgorithmsAssertions.Swap(ref arr[index], ref arr[minElementIndex]);
        }

        Debug.Assert(ValidateIfArrayIsSorted(arr), "Array is not sorted.");
    }