/* template<class _FwdIt, class _Ty> bool binary_search(_FwdIt _First, _FwdIt _Last, const _Ty& _Val) template<class _FwdIt, class _Ty, class _Pr> bool binary_search(_FwdIt _First, _FwdIt _Last, const _Ty& _Val, _Pr _Pred) */ #include <algorithm> #include <iostream> #include <functional> using namespace std; int main() { //ソートされている必要がある int a[] = {1,2,4,7,9}; //true cout << ( binary_search(a,a+5,4) ? "true" : "false" ) << endl; //false cout << ( binary_search(a,a+5,3) ? "true" : "false" ) << endl; sort(a, a+5, greater<int>()); //false 第3引数でソートされた配列を2分検索する cout << ( binary_search(a,a+5,3,greater<int>()) ? "true" : "false" ) << endl; }
最近作成されたWikiのアクセスランキングです。見るだけでなく加筆してみよう!
atwikiでよく見られているWikiのランキングです。新しい情報を発見してみよう!
最近アクセスの多かったページランキングです。話題のページを見に行こう!