示例#1
0
        /// <summary>
        /// Finds min 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>
        public static int CalculateValue(ComparerRowMin _, int[] row)
        {
            var value = int.MaxValue;

            for (var i = 0; i < row.Length; i++)
            {
                if (row[i] < value)
                {
                    value = row[i];
                }
            }
            return(value);
        }
        /// <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));
        }
示例#3
0
        /// <summary>
        /// Finds min 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(ComparerRowMinReverse _, int[] row)
        {
            ComparerRowMin dummy = null;

            return(CalculateValue(dummy, row));
        }