Created
June 20, 2013 08:16
-
-
Save dodola/5821074 to your computer and use it in GitHub Desktop.
二分法查找
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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