public static void BubbleSortWithDlgt(int[][] jaggedArray, CompareDlgt cdlgt)
            {
                if (jaggedArray == null)
                {
                    throw new ArgumentNullException(nameof(jaggedArray));
                }

                for (int i = 1; i < jaggedArray.Length; i++)
                {
                    for (int j = 0; j < jaggedArray.Length - 1; j++)
                    {
                        if (cdlgt(jaggedArray[j], jaggedArray[j + 1]) > 0)
                        {
                            Swap(ref jaggedArray[j], ref jaggedArray[j + 1]);
                        }
                    }
                }
            }
Example #2
0
        public void ComparerMinByDecWithDelegateTest()
        {
            int[][] jaggedArray = new int[3][];
            jaggedArray[0] = new int[4] {
                1, 2, 3, 40
            };
            jaggedArray[2] = new int[6] {
                1, 2, 3, 4, -1, -2
            };

            int[][] expected = new int[3][];
            expected[1] = jaggedArray[0];
            expected[2] = jaggedArray[2];

            ComparerMinByDec cmbd = new ComparerMinByDec();
            CompareDlgt      dlgt = cmbd.Compare;

            ArrayHelper.BubbleSortWithDlgt(jaggedArray, dlgt);

            CollectionAssert.AreEqual(expected, jaggedArray);
        }