Skip to content

Commit 4b444f4

Browse files
author
Fahham29
committed
Fix syntax and add find(Integer[], Integer) method
1 parent 4d4ab19 commit 4b444f4

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/main/java/com/thealgorithms/searches/JumpSearch.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public static int jumpSearch(int[] arr, int target) {
2525
while (prev < n && arr[Math.min(step, n) - 1] < target) {
2626
prev = step;
2727
step += (int) Math.floor(Math.sqrt(n));
28-
2928
}
3029

3130
for (int i = prev; i < Math.min(step, n); i++) {
@@ -36,4 +35,19 @@ public static int jumpSearch(int[] arr, int target) {
3635

3736
return -1;
3837
}
38+
39+
/**
40+
* Wrapper method to support Integer[] for testing purposes.
41+
*
42+
* @param arr array of Integers
43+
* @param target target value
44+
* @return index if found, else -1
45+
*/
46+
public static int find(Integer[] arr, Integer target) {
47+
int[] array = new int[arr.length];
48+
for (int i = 0; i < arr.length; i++) {
49+
array[i] = arr[i];
50+
}
51+
return jumpSearch(array, target);
52+
}
3953
}

0 commit comments

Comments
 (0)