Exemplo n.º 1
0
        public static void TestPrintMatrixInSpiral()
        {
            int[,] mat = MatrixProblemHelper.CreateMatrix(4, 4);
            MatrixProblemHelper.PrintMatrix(mat);

            Console.WriteLine("The matrix spirally is as shown below:");
            Print(mat);

            mat = MatrixProblemHelper.CreateMatrix(3, 2);
            MatrixProblemHelper.PrintMatrix(mat);

            Console.WriteLine("The matrix spirally is as shown below:");
            Print(mat);

            mat = MatrixProblemHelper.CreateMatrix(2, 3);
            MatrixProblemHelper.PrintMatrix(mat);

            Console.WriteLine("The matrix spirally is as shown below:");
            Print(mat);

            mat = MatrixProblemHelper.CreateMatrix(3, 3);
            MatrixProblemHelper.PrintMatrix(mat);


            Console.WriteLine("The matrix spirally is as shown below:");
            Print(mat);

            mat = MatrixProblemHelper.CreateMatrix(3, 4);
            MatrixProblemHelper.PrintMatrix(mat);


            Console.WriteLine("The matrix spirally is as shown below:");
            Print(mat);
        }
Exemplo n.º 2
0
        public static void TestRotateMatrix()
        {
            Rotate_Matrix_90_degree rtMat = new Rotate_Matrix_90_degree();

            int[,] mat = MatrixProblemHelper.CreateMatrix(4, 4);
            MatrixProblemHelper.PrintMatrix(mat);
            Console.WriteLine();
            mat = rtMat.RotateMatrix(mat);
            MatrixProblemHelper.PrintMatrix(mat);
        }
Exemplo n.º 3
0
        public static void TestRotateMatrix180()
        {
            int[,] mat = MatrixProblemHelper.CreateMatrix(4,5);
            Console.WriteLine("The actual matrix");
            MatrixProblemHelper.PrintMatrix(mat);

            Console.WriteLine("Rotate matrix 180 degree");
            RotateMatrix180 rotateMat = new RotateMatrix180();
            rotateMat.RotateMatrix180Degree(mat);
            MatrixProblemHelper.PrintMatrix(mat);
        }
        public static void TestSumOfMatrixElements()
        {
            int[,] mat = MatrixProblemHelper.CreateMatrix(4, 5);
            Console.WriteLine("The actual matrix");
            MatrixProblemHelper.PrintMatrix(mat);

            Console.WriteLine("Sum of matrix elements in the rectangle");
            SumOfMatrixElementsFormedByRectangleWithCoordinates sumMat = new SumOfMatrixElementsFormedByRectangleWithCoordinates();

            mat = sumMat.PreProcessMatrix(mat);
            MatrixProblemHelper.PrintMatrix(mat);

            Console.WriteLine("the area is: " + sumMat.GetArea(2, 2, 3, 4, mat));
        }
        public static void TestMakeRowColZero1()
        {
            int[,] mat = MatrixProblemHelper.CreateMatrix(4, 5);
            // Make a few places 0
            Random rnd = new Random();

            mat[rnd.Next(0, 4), rnd.Next(0, 5)] = 0;
            mat[rnd.Next(0, 4), rnd.Next(0, 5)] = 0;
            Console.WriteLine("original matrix");
            MatrixProblemHelper.PrintMatrix(mat);
            Console.WriteLine();

            Console.WriteLine("all affected rows and columns are 0 using Algorithm 1");
            mat = MakeRowColZero1(mat);
            MatrixProblemHelper.PrintMatrix(mat);
        }