April 2018
Intermediate to advanced
322 pages
6h 57m
English
If we want to find the position of 39 in the array, as we did earlier in this chapter, we can use the following main() function:
int main(){ cout << "Jump Search" << endl; // Initialize a new array int arr[] = {8, 15, 23, 28, 32, 39, 42, 44, 47, 48}; int arrSize = sizeof(arr)/sizeof(*arr); // Define value to be searched int searchedValue = 39; // Find the searched value using Jump Search int i = JumpSearch(arr, arrSize, searchedValue); // Notify user the result // if the return is not -1, // the searched value is found if(i != -1) { cout << searchedValue << " is found in index "; cout << i << endl; } else { cout << "Could not find value " << searchedValue; cout << endl; } return 0;}
If we build and run the preceding ...