Skip to content

Commit 255a507

Browse files
committed
refactoring to correct package
1 parent 7c5351e commit 255a507

12 files changed

+84
-75
lines changed

src/main/java/com/thealgorithms/misc/InverseOfMatrix.java renamed to src/main/java/com/thealgorithms/matrix/InverseOfMatrix.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.thealgorithms.misc;
1+
package com.thealgorithms.matrix;
22

33
/**
44
* This class provides methods to compute the inverse of a square matrix

src/main/java/com/thealgorithms/misc/MatrixTranspose.java renamed to src/main/java/com/thealgorithms/matrix/MatrixTranspose.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.thealgorithms.misc;
1+
package com.thealgorithms.matrix;
22

33
/**
44
*

src/main/java/com/thealgorithms/misc/MedianOfMatrix.java renamed to src/main/java/com/thealgorithms/matrix/MedianOfMatrix.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.thealgorithms.misc;
1+
package com.thealgorithms.matrix;
22

33
import java.util.ArrayList;
44
import java.util.Collections;

src/main/java/com/thealgorithms/misc/MirrorOfMatrix.java renamed to src/main/java/com/thealgorithms/matrix/MirrorOfMatrix.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.thealgorithms.misc;
1+
package com.thealgorithms.matrix;
22

33
// Problem Statement
44
/*
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,62 @@
1-
package com.thealgorithms.others;
2-
3-
import java.util.ArrayList;
4-
import java.util.List;
5-
6-
public class PrintAMatrixInSpiralOrder {
7-
/**
8-
* Search a key in row and column wise sorted matrix
9-
*
10-
* @param matrix matrix to be searched
11-
* @param row number of rows matrix has
12-
* @param col number of columns matrix has
13-
* @author Sadiul Hakim : https://github.com/sadiul-hakim
14-
*/
15-
16-
public List<Integer> print(int[][] matrix, int row, int col) {
17-
18-
// r traverses matrix row wise from first
19-
int r = 0;
20-
// c traverses matrix column wise from first
21-
int c = 0;
22-
int i;
23-
24-
List<Integer> result = new ArrayList<>();
25-
26-
while (r < row && c < col) {
27-
// print first row of matrix
28-
for (i = c; i < col; i++) {
29-
result.add(matrix[r][i]);
30-
}
31-
32-
// increase r by one because first row printed
33-
r++;
34-
35-
// print last column
36-
for (i = r; i < row; i++) {
37-
result.add(matrix[i][col - 1]);
38-
}
39-
40-
// decrease col by one because last column has been printed
41-
col--;
42-
43-
// print rows from last except printed elements
44-
if (r < row) {
45-
for (i = col - 1; i >= c; i--) {
46-
result.add(matrix[row - 1][i]);
47-
}
48-
49-
row--;
50-
}
51-
52-
// print columns from first except printed elements
53-
if (c < col) {
54-
for (i = row - 1; i >= r; i--) {
55-
result.add(matrix[i][c]);
56-
}
57-
c++;
58-
}
59-
}
60-
return result;
61-
}
62-
}
1+
package com.thealgorithms.matrix;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class PrintAMatrixInSpiralOrder {
7+
/**
8+
* Search a key in row and column wise sorted matrix
9+
*
10+
* @param matrix matrix to be searched
11+
* @param row number of rows matrix has
12+
* @param col number of columns matrix has
13+
* @author Sadiul Hakim : https://github.com/sadiul-hakim
14+
*/
15+
16+
public List<Integer> print(int[][] matrix, int row, int col) {
17+
18+
// r traverses matrix row wise from first
19+
int r = 0;
20+
// c traverses matrix column wise from first
21+
int c = 0;
22+
int i;
23+
24+
List<Integer> result = new ArrayList<>();
25+
26+
while (r < row && c < col) {
27+
// print first row of matrix
28+
for (i = c; i < col; i++) {
29+
result.add(matrix[r][i]);
30+
}
31+
32+
// increase r by one because first row printed
33+
r++;
34+
35+
// print last column
36+
for (i = r; i < row; i++) {
37+
result.add(matrix[i][col - 1]);
38+
}
39+
40+
// decrease col by one because last column has been printed
41+
col--;
42+
43+
// print rows from last except printed elements
44+
if (r < row) {
45+
for (i = col - 1; i >= c; i--) {
46+
result.add(matrix[row - 1][i]);
47+
}
48+
49+
row--;
50+
}
51+
52+
// print columns from first except printed elements
53+
if (c < col) {
54+
for (i = row - 1; i >= r; i--) {
55+
result.add(matrix[i][c]);
56+
}
57+
c++;
58+
}
59+
}
60+
return result;
61+
}
62+
}

src/main/java/com/thealgorithms/others/RotateMatrixBy90Degrees.java renamed to src/main/java/com/thealgorithms/matrix/RotateMatrixBy90Degrees.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.thealgorithms.others;
1+
package com.thealgorithms.matrix;
22

33
import java.util.Scanner;
44
/**

src/main/java/com/thealgorithms/matrixexponentiation/Fibonacci.java renamed to src/main/java/com/thealgorithms/matrix/matrixexponentiation/Fibonacci.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.thealgorithms.matrixexponentiation;
1+
package com.thealgorithms.matrix.matrixexponentiation;
22

33
import java.util.Scanner;
44

src/test/java/com/thealgorithms/misc/InverseOfMatrixTest.java renamed to src/test/java/com/thealgorithms/matrix/InverseOfMatrixTest.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
package com.thealgorithms.misc;
2-
3-
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
1+
package com.thealgorithms.matrix;
42

53
import java.util.stream.Stream;
4+
5+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
66
import org.junit.jupiter.params.ParameterizedTest;
77
import org.junit.jupiter.params.provider.Arguments;
88
import org.junit.jupiter.params.provider.MethodSource;
99

10+
1011
class InverseOfMatrixTest {
1112

1213
@ParameterizedTest

src/test/java/com/thealgorithms/misc/MatrixTransposeTest.java renamed to src/test/java/com/thealgorithms/matrix/MatrixTransposeTest.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.thealgorithms.misc;
1+
package com.thealgorithms.matrix;
22

33
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
44
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -8,6 +8,8 @@
88
import org.junit.jupiter.params.provider.Arguments;
99
import org.junit.jupiter.params.provider.MethodSource;
1010

11+
import com.thealgorithms.matrix.MatrixTranspose;
12+
1113
public class MatrixTransposeTest {
1214

1315
private static Stream<Arguments> provideValidMatrixTestCases() {

src/test/java/com/thealgorithms/misc/MedianOfMatrixTest.java renamed to src/test/java/com/thealgorithms/matrix/MedianOfMatrixTest.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.thealgorithms.misc;
1+
package com.thealgorithms.matrix;
22

33
import static org.junit.jupiter.api.Assertions.assertEquals;
44

@@ -7,6 +7,8 @@
77
import java.util.List;
88
import org.junit.jupiter.api.Test;
99

10+
import com.thealgorithms.matrix.MedianOfMatrix;
11+
1012
public class MedianOfMatrixTest {
1113

1214
@Test

src/test/java/com/thealgorithms/misc/MirrorOfMatrixTest.java renamed to src/test/java/com/thealgorithms/matrix/MirrorOfMatrixTest.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
package com.thealgorithms.misc;
1+
package com.thealgorithms.matrix;
22

33
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
44
import static org.junit.jupiter.api.Assertions.assertNull;
55
import static org.junit.jupiter.api.Assertions.assertThrows;
66

77
import org.junit.jupiter.api.Test;
88

9+
import com.thealgorithms.matrix.MirrorOfMatrix;
10+
911
class MirrorOfMatrixTest {
1012

1113
@Test

src/test/java/com/thealgorithms/others/TestPrintMatrixInSpiralOrder.java renamed to src/test/java/com/thealgorithms/matrix/TestPrintMatrixInSpiralOrder.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
package com.thealgorithms.others;
1+
package com.thealgorithms.matrix;
22

33
import static org.junit.jupiter.api.Assertions.assertIterableEquals;
44

55
import java.util.List;
66
import org.junit.jupiter.api.Test;
77

8+
import com.thealgorithms.matrix.PrintAMatrixInSpiralOrder;
9+
810
public class TestPrintMatrixInSpiralOrder {
911
@Test
1012
public void testOne() {

0 commit comments

Comments
 (0)