Ejemplo n.º 1
0
        /// <summary>
        /// Sorts jugged array by Bubble Algorithm with come comparator
        /// </summary>
        /// <param name="arr">jugged array</param>
        /// <param name="comparator">implements comparation way</param>
        /// <exception cref="ArgumentNullException"></exception>
        public static void SortJuggedArray(int[][] arr, ICustomComparator comparator)
        {
            if (arr == null)
            {
                throw new ArgumentNullException(nameof(arr));
            }
            if (comparator == null)
            {
                throw new ArgumentNullException(nameof(comparator));
            }

            for (int i = 0; i < arr.Length - 1; i++)
            {
                for (int j = i + 1; j < arr.Length; j++)
                {
                    if (comparator.CompareArrays(arr[i], arr[j]) <= 0)
                    {
                        continue;
                    }
                    var temp = arr[i];
                    arr[i] = arr[j];
                    arr[j] = temp;
                }
            }
        }
 public void TestSortJuggedArrayThrows(int[][] arr, ICustomComparator comparator)
 {
     Assert.That(() => BubbleSort.SortJuggedArray(arr, comparator), Throws.TypeOf <ArgumentNullException>());
 }
 public int[][] TestSortJuggedArray(int[][] arr, ICustomComparator comparator)
 {
     BubbleSort.SortJuggedArray(arr, comparator);
     return(arr);
 }