Ejemplo n.º 1
0
        /// <summary>
        /// Finds sum of 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(ComparerRowSum _, int[] row)
        {
            var value = 0;

            for (var i = 0; i < row.Length; i++)
            {
                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));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Finds sum of 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(ComparerRowSumReverse _, int[] row)
        {
            ComparerRowSum dummy = null;

            return(CalculateValue(dummy, row));
        }