Two-point search:
Binary search also known as binary lookup, the advantages are less than the number of comparisons, Find Fast, the average performance is good, the disadvantage is that the unknown origin table is ordered table, and insert delete difficult.
The code is not many, just a few lines; main start = 0; end = nlength-1;while (start <= end);
#include <iostream>using namespace std; /* Run this program using the console Pauser or add your own getch, System ("pause") or input loop */int bianrysearch (int a [], int nlength, int val) {int start = 0;int End = Nlength-1;int index = -1;while (start<=end) {index = (start+ end)/2;i F (a[index] = = val) {return index;} else if (A[index] < val) {start = index + 1;} Else{end = Index-1;}} return-1;} int main (int argc, char** argv) {int a[] = {0,1,2,3,4,5};for (int i = 0; i < 6; i++) {cout<<a[i]<< "";} int k =bianrysearch (a,sizeof (a)/sizeof (int), 5);cout<< "5 in Position:"; Cout<<k<<endl;return 0;}
The binary search of C + + algorithm