Skip to content

Instantly share code, notes, and snippets.

@dodola
Created June 20, 2013 08:16
Show Gist options
  • Save dodola/5821074 to your computer and use it in GitHub Desktop.
Save dodola/5821074 to your computer and use it in GitHub Desktop.
二分法查找
#include<iostream>
using namespace std;
bool bin_search(int nums[],int i,int len){
int left=0,right=len-1,middle;
while(left<=right){
middle=left+((right-left)>>1);
if(i>nums[middle]){
left=middle+1;
}else if(i<nums[middle]){
right=middle-1;
}else return true;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment