A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://TheAlgorithms.github.io/C-Plus-Plus/d2/d22/jump__search_8cpp_source.html below:

TheAlgorithms/C++: search/jump_search.cpp Source File

Go to the documentation of this file. 13 // Finding block size to be jumped 14 int

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 int

arr[] = {0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610};

47 int

n =

sizeof

(arr) /

sizeof

(arr[0]);

49 // Find the index of 'x' using Jump Search 52 // Print the index where 'x' is located 53

std::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