コード例 #1
0
        /// <summary>
        /// A method of sorting matrix rows by descending maximal elements of rows.
        /// </summary>
        /// <param name="array">Input array.</param>
        /// <returns>Sorted array.</returns>
        public int[,] SortArray(int[,] array)
        {
            for (int i = 0; i < array.GetLength(0); i++)
            {
                for (int j = 1; j < array.GetLength(0); j++)
                {
                    int previousMax = SortHelper.FindMaxInRow(array, j - 1),
                        currentMax  = SortHelper.FindMaxInRow(array, j);

                    if (previousMax < currentMax)
                    {
                        SortHelper.SwapCurrentStringWithPrevious(array, j);
                    }
                }
            }

            return(array);
        }
コード例 #2
0
ファイル: SortMethods.cs プロジェクト: vrmthdrth/dotnet-epam
        /// <summary>
        /// A method of sorting matrix rows by ascending maximal elements of rows.
        /// </summary>
        /// <param name="matrix">Input array.</param>
        /// <returns>Sorted array.</returns>
        public static Matrix AscendingByMax(Matrix matrix)
        {
            for (int i = 0; i < matrix.Values.GetLength(0); i++)
            {
                for (int j = 1; j < matrix.Values.GetLength(0); j++)
                {
                    int previousMax = SortHelper.FindMaxInRow(matrix.Values, j - 1),
                        currentMax  = SortHelper.FindMaxInRow(matrix.Values, j);

                    if (previousMax > currentMax)
                    {
                        SortHelper.SwapCurrentStringWithPrevious(matrix.Values, j);
                    }
                }
            }

            return(matrix);
        }