1 Recursive is God , It's people that iterate
-- Iterative half search -- Recursive half search
2 See case (zhebanchazhao1.cpp)
/** * This case demonstrates recursive half search and iterative half search * */ #include <iostream> using namespace std; //
Recursive half search arg1: Array to find   arg2: Elements in array to find arg3 arg4: Need to find the bottom corner of both sides of the array If 10 number , be left=0
right = 9 int BinarySearch_I(int* a, const int x, const int left, const int
right); // Iterative half search int BinarySearch_R(int* a, const int x, const int n); int
main() { int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; int result = BinarySearch_R(
a, 7, 10); if(result == -1) cout << " The element is not in the array " << endl; else cout <<
" The elements in the array are in the a[" << result << "] in " << endl; int result2 = BinarySearch_I(a, 6, 0, 9)
; if(result2 == -1) cout << " The element is not in the array " << endl; else cout << " The elements in the array are in the a[" <<
result2<< "] in " << endl; return 0; } // Iterative half search int BinarySearch_R(int* a, const
int x, const int n) { int left = 0, right = n - 1, middle; while(left <= right)
// Always binary search , If found , Then return the following table of the array of elements { middle = (left + right) / 2; if(x == a[middle])
return middle; else if(x > a[middle]) left = middle + 1; else if(x < a[middle])
right= middle - 1; } return -1; // If while Loop not found , Then return -1 } // Recursive half search int
BinarySearch_I(int* a, const int x, const int left, const int right) { while(
left<= right) { int middle = (left + right) / 2; // Halve if(x < a[middle]) return
BinarySearch_I(a, x, left, middle -1); else if(x > a[middle]) return
BinarySearch_I(a, x, middle + 1, right); else return middle; } return -1; }

Technology
©2019-2020 Toolsou All rights reserved,
Mybatis Error resolution :There is no getter for property named '*' in 'class Java.lang.String Big data tells you , How tired are Chinese women Message quality platform series | Full link troubleshooting Gude Haowen serial - You deserve to be an engineer ( Preface ) Image explanation of over fitting and under fitting Springboot of JPA Common query methods JAVA Detailed explanation of anomalies vue Of v-if And v-show The difference between python To solve the problem of dictionary writing list in Codeup——601 | problem A: task scheduling