step = std::sqrt(n);
16 // Finding the block where element is 17 // present (if it is present) 19 while(arr[std::min(step, n) - 1] < x) {
26 // Doing a linear search for x in block 27 // beginning with prev. 28 while(arr[prev] < x) {
31 // If we reached next block or end of 32 // array, element is not present. 33 if(prev == std::min(step, n))
36 // If element is found 43// Driver program to test function 45 intarr[] = {0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610};
47 intn =
sizeof(arr) /
sizeof(arr[0]);
49 // Find the index of 'x' using Jump Search 52 // Print the index where 'x' is located 53std::cout <<
"\nNumber "<< x <<
" is at index "<< index;
int main()
Main function.
int jumpSearch(int arr[], int x, int n)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4