Skip to content

Commit 4964b61

Browse files
committed
add change
1 parent f1e2606 commit 4964b61

File tree

4 files changed

+379
-379
lines changed

4 files changed

+379
-379
lines changed
Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
package com.thealgorithms.bitmanipulation;
2-
3-
/*
4-
* Author: lukasb1b (https://github.com/lukasb1b)
5-
*/
6-
7-
public final class SingleBitOperations {
8-
private SingleBitOperations() {
9-
}
10-
/**
11-
* Flip the bit at position 'bit' in 'num'
12-
*/
13-
public static int flipBit(final int num, final int bit) {
14-
return num ^ (1 << bit);
15-
}
16-
/**
17-
* Set the bit at position 'bit' to 1 in the 'num' variable
18-
*/
19-
public static int setBit(final int num, final int bit) {
20-
return num | (1 << bit);
21-
}
22-
/**
23-
* Clears the bit located at 'bit' from 'num'
24-
*/
25-
public static int clearBit(final int num, final int bit) {
26-
return num & ~(1 << bit);
27-
}
28-
/**
29-
* Get the bit located at 'bit' from 'num'
30-
*/
31-
public static int getBit(final int num, final int bit) {
32-
return ((num >> bit) & 1);
33-
}
34-
}
1+
package com.thealgorithms.bitmanipulation;
2+
3+
/*
4+
* Author: lukasb1b (https://github.com/lukasb1b)
5+
*/
6+
7+
public final class SingleBitOperations {
8+
private SingleBitOperations() {
9+
}
10+
/**
11+
* Flip the bit at position 'bit' in 'num'
12+
*/
13+
public static int flipBit(final int num, final int bit) {
14+
return num ^ (1 << bit);
15+
}
16+
/**
17+
* Set the bit at position 'bit' to 1 in the 'num' variable
18+
*/
19+
public static int setBit(final int num, final int bit) {
20+
return num | (1 << bit);
21+
}
22+
/**
23+
* Clears the bit located at 'bit' from 'num'
24+
*/
25+
public static int clearBit(final int num, final int bit) {
26+
return num & ~(1 << bit);
27+
}
28+
/**
29+
* Get the bit located at 'bit' from 'num'
30+
*/
31+
public static int getBit(final int num, final int bit) {
32+
return ((num >> bit) & 1);
33+
}
34+
}
Lines changed: 62 additions & 62 deletions
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.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+
}
Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
package com.thealgorithms.searches;
2-
3-
public class SearchInARowAndColWiseSortedMatrix {
4-
/**
5-
* Search a key in row and column wise sorted matrix
6-
*
7-
* @param matrix matrix to be searched
8-
* @param value Key being searched for
9-
* @author Sadiul Hakim : https://github.com/sadiul-hakim
10-
*/
11-
12-
public int[] search(int[][] matrix, int value) {
13-
int n = matrix.length;
14-
// This variable iterates over rows
15-
int i = 0;
16-
// This variable iterates over columns
17-
int j = n - 1;
18-
int[] result = {-1, -1};
19-
20-
while (i < n && j >= 0) {
21-
if (matrix[i][j] == value) {
22-
result[0] = i;
23-
result[1] = j;
24-
return result;
25-
}
26-
if (value > matrix[i][j]) {
27-
i++;
28-
} else {
29-
j--;
30-
}
31-
}
32-
return result;
33-
}
34-
}
1+
package com.thealgorithms.searches;
2+
3+
public class SearchInARowAndColWiseSortedMatrix {
4+
/**
5+
* Search a key in row and column wise sorted matrix
6+
*
7+
* @param matrix matrix to be searched
8+
* @param value Key being searched for
9+
* @author Sadiul Hakim : https://github.com/sadiul-hakim
10+
*/
11+
12+
public int[] search(int[][] matrix, int value) {
13+
int n = matrix.length;
14+
// This variable iterates over rows
15+
int i = 0;
16+
// This variable iterates over columns
17+
int j = n - 1;
18+
int[] result = {-1, -1};
19+
20+
while (i < n && j >= 0) {
21+
if (matrix[i][j] == value) {
22+
result[0] = i;
23+
result[1] = j;
24+
return result;
25+
}
26+
if (value > matrix[i][j]) {
27+
i++;
28+
} else {
29+
j--;
30+
}
31+
}
32+
return result;
33+
}
34+
}

0 commit comments

Comments
 (0)