/// <summary>
        /// Sorts the rows of the matrix.
        /// </summary>
        /// <param name="matrix">Matrix to sort.</param>
        /// <param name="sortBy">Sorting criterion./></param>
        /// <returns></returns>
        public int[,] Sort(int[,] matrix, SortCriteria sortBy)
        {
            // convert matrix to List of rows.
            this.matrixAsList = generateMatrixAsList(matrix);

            // choose comparer method
            IComparer <int[]> comparer = null;

            switch (sortBy)
            {
            case SortCriteria.RowSum:
                comparer = new ComparerRowSum();
                break;

            case SortCriteria.RowSumReverse:
                comparer = new ComparerRowSumReverse();
                break;

            case SortCriteria.RowMax:
                comparer = new ComparerRowMax();
                break;

            case SortCriteria.RowMaxReverse:
                comparer = new ComparerRowMaxReverse();
                break;

            case SortCriteria.RowMin:
                comparer = new ComparerRowMin();
                break;

            case SortCriteria.RowMinReverse:
                comparer = new ComparerRowMinReverse();
                break;

            default:
                break;
            }

            // apply List<T>.Sort method.
            this.matrixAsList.Sort(comparer);

            // convert List of rows back to matrix.
            return(generateMatrixAsArray(matrixAsList));
        }
예제 #2
0
        /// <summary>
        /// Finds max value among the elements of the row.
        /// </summary>
        /// <param name="_">Only type of this discard is important for choosing the method.</param>
        /// <param name="row">Row of matrix.</param>
        /// <returns></returns>
        /// <remarks>Actually calls the other method as the function is the same.</remarks>
        public static int CalculateValue(ComparerRowMaxReverse _, int[] row)
        {
            ComparerRowMax dummy = null;

            return(CalculateValue(dummy, row));
        }