/// <summary> /// Sort by sum 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 BubbleSortSumElements(ref int[][] matrixInts, ISort sort, bool flag) { if (ReferenceEquals(matrixInts, null) || ReferenceEquals(sort, null)) { throw new ArgumentNullException(); } var sizeRow = matrixInts.GetLength(0); int[] sumInts = SumArrayLine(matrixInts, sizeRow); for (var i = 0; i < sizeRow - 1; i++) { for (var j = i; j < matrixInts.Length; j++) { if (flag) { if (sort.SortSum(sumInts[i], sumInts[j])) { continue; } } else { if (!(sort.SortSum(sumInts[i], sumInts[j]))) { continue; } } ChangeArrayIndex(ref matrixInts, i, j); Swap(ref sumInts[i], ref sumInts[j]); } } }