/// <summary> /// Sort by min amount of bubble elements. /// </summary> /// <param name="matrixInts">Integer matrix elements</param> /// <param name="sort">Interface realization</param> /// <param name="flag">Sorting direction</param> public static void BubbleSortMinElements(ref int[][] matrixInts, ISort sort, bool flag) { if (ReferenceEquals(matrixInts, null) || ReferenceEquals(sort, null)) { throw new ArgumentNullException(); } var sizeRow = matrixInts.GetLength(0); int[] minInts = MinVal(matrixInts, sizeRow); for (var i = 0; i < sizeRow; i++) { for (var j = i; j < matrixInts.Length; j++) { if (flag) { if (sort.SortMin(minInts[i], minInts[j])) { continue; } } else { if (!sort.SortMin(minInts[i], minInts[j])) { continue; } } ChangeArrayIndex(ref matrixInts, i, j); Swap(ref minInts[i], ref minInts[j]); } } }