1 //binary_search用于在有序的区间用拆半查找搜索等于某值得元素 2 #include<algorithm> 3 #include<iostream> 4 5 using namespace std; 6 7 int main() 8 { 9 int a[] = {3, 9, 17, 22, 23, 24}; 10 11 const int len = sizeof(a)/sizeof(int); 12 13 if(binary_search(a, a+len, 24)) 14 cout<<"数组包含24"<<endl; 15 else 16 cout<<"数组不包含24"<<endl; 17 18 system("pause"); 19 20 return 0; 21 }