private static void Main()
        {
            Console.Title = "Lrgest area of equal neighbour elements in matrix";

            /*// Inputs
             * Console.WriteLine("Enter dimensions");
             * int rows = new int();
             * rows = Input("first dimension N");
             * int cols = new int();
             * cols = Input("second dimension M");
             * Console.WriteLine();*/

            int[,] matrix =
            {
                { 1, 3, 2, 2, 2, 4 },
                { 3, 3, 3, 2, 4, 4 },
                { 4, 3, 3, 2, 3, 3 },
                { 4, 3, 3, 3, 3, 1 },
                { 4, 3, 3, 3, 1, 1 }
            }; // new int[rows, cols];

            // MtrxInput(matrix);

            // Print
            PrintMatrix(matrix);

            // Solve
            bool[,] visited = new bool[matrix.GetLength(0), matrix.GetLength(1)];
            EqualElement max = FindMaxArea(matrix, visited);

            Console.WriteLine("Maximal area consists of {0} elements of {1}", max.Counter, max.Element);
        }
        private static EqualElement FindMaxArea(int[,] matrix, bool[,] visited)
        {
            int maxCounter = int.MinValue;
            int element    = new int();

            for (int row = 0; row < matrix.GetLength(0); row++)
            {
                for (int col = 0; col < matrix.GetLength(1); col++)
                {
                    // Recursive method to find equal elements
                    int counter = new int();
                    FindEquals(visited, matrix, row, col, matrix[row, col], ref counter);

                    if (counter > maxCounter)
                    {
                        maxCounter = counter;
                        element    = matrix[row, col];
                    }
                }
            }

            EqualElement max = new EqualElement();

            {
                max.Counter = maxCounter;
                max.Element = element;
            }

            return(max);
        }
Example #3
0
        private static EqualElement FindMaxArea(int[,] matrix, bool[,] visited)
        {
            int maxCounter = int.MinValue;
            int element = new int();

            for (int row = 0; row < matrix.GetLength(0); row++)
            {
                for (int col = 0; col < matrix.GetLength(1); col++)
                {
                    // Recursive method to find equal elements
                    int counter = new int();
                    FindEquals(visited, matrix, row, col, matrix[row, col], ref counter);

                    if (counter > maxCounter)
                    {
                        maxCounter = counter;
                        element = matrix[row, col];
                    }
                }
            }

            EqualElement max = new EqualElement();
            {
                max.Counter = maxCounter;
                max.Element = element;
            }

            return max;
        }