public class JumpSearch {
public int jumpsearch(int[]array, int target) {
int blockSize = (int) Math.sqrt(array.length);
int start = 0;
int next = blockSize;
while (start < array.length && array[next - 1] < target) {
start = next;
next += blockSize;
if (next > array.length)
next = array.length;
}
for (var i = start; i < next; i++)
if (array[i] == target)
return i;
return -1;
}
}
Test case failed:
Array : int[] array = {2,8,7,9,15,19}; " unsorted "
var index = search.jumpsearch(array,7);
System.out.println(index);