GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Data-Structures/cpp/JumpSearch.cpp at main · karankeyash/Data-Structures Expand file tree/ Copy pathJumpSearch.cppMore file actions 42 lines (36 loc) · 987 Bytes / Copy pathJumpSearch.cppFile metadata and controls42 lines (36 loc) · 987 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 #include<iostream> #include<cmath> using namespace std; int jump_Search(int a[], int n, int item) { int i = 0; int m = sqrt(n); while(a[m] <= item && m < n) { // the control will continue to jump the blocks i = m; // shift the block m += sqrt(n); if(m > n - 1) // if m exceeds the array size return -1; } for(int x = i; x<m; x++) { //linear search in current block if(a[x] == item) return x; //position of element being searched } return -1; } int main() { int n, item, loc; cout << "\n Enter number of items: "; cin >> n; int arr[n]; //creating an array of size n cout << "\n Enter items: "; for(int i = 0; i< n; i++) { cin >> arr[i]; } cout << "\n Enter search key to be found in the array: "; cin >> item; loc = jump_Search(arr, n, item); if(loc>=0) cout << "\n Item found at location: " << loc; else cout << "\n Item is not found in the list."; } |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |