青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

Benjamin

靜以修身,儉以養德,非澹薄無以明志,非寧靜無以致遠。
隨筆 - 398, 文章 - 0, 評論 - 196, 引用 - 0
數據加載中……

STL算法(Algorithms):極值

1、min:返回兩個兩個參數中的最小值
原型:template <class T> const T& min ( const T& a, const T& b );
template <class T, class Compare>
  const T& min ( const T& a, const T& b, Compare comp );
示例:
// min example
#include <iostream>
#include <algorithm>
using namespace std;

int main () {
cout << "min(1,2)==" << min(1,2) << endl;
  cout << "min(2,1)==" << min(2,1) << endl;
  cout << "min('a','z')==" << min('a','z') << endl;
  cout << "min(3.14,2.72)==" << min(3.14,2.72) << endl;
  return 0;
}
2、max:返回兩個參數中的大值
原型:
template <class T> const T& max ( const T& a, const T& b );
template <class T, class Compare>
  const T& max ( const T& a, const T& b, Compare comp );
示例:
// max example
#include <iostream>
#include <algorithm>
using namespace std;

int main () { cout << "max(1,2)==" << max(1,2) << endl;
  cout << "max(2,1)==" << max(2,1) << endl;
  cout << "max('a','z')==" << max('a','z') << endl;
  cout << "max(3.14,2.73)==" << max(3.14,2.73) << endl;
  return 0;
}
3、min_element:返回(迭代器)指定范圍內的最小元素
原型:
// min_element/max_element
#include <iostream>
#include <algorithm>
using namespace std;

bool myfn(int i, int j) { return i<j; }

struct myclass {
  bool operator() (int i,int j) { return i<j; }
} myobj;

int main () {
  int myints[] = {3,7,2,5,6,4,9};

  // using default comparison:
  cout << "The smallest element is " << *min_element(myints,myints+7) << endl;
  cout << "The largest element is " << *max_element(myints,myints+7) << endl;

  // using function myfn as comp:
  cout << "The smallest element is " << *min_element(myints,myints+7,myfn) << endl;
  cout << "The largest element is " << *max_element(myints,myints+7,myfn) << endl;

  // using object myobj as comp:
  cout << "The smallest element is " << *min_element(myints,myints+7,myobj) << endl; cout << "The largest element is " << *max_element(myints,myints+7,myobj) << endl;

  return 0;
}
4、max_element:返回(迭代器)指定范圍內的最小元素
原型:
template <class ForwardIterator>
  ForwardIterator max_element ( ForwardIterator first, ForwardIterator last );

template <class ForwardIterator, class Compare>
  ForwardIterator max_element ( ForwardIterator first, ForwardIterator last,
                                Compare comp );
示例:
// min_element/max_element
#include <iostream>
#include <algorithm>
using namespace std;

bool myfn(int i, int j) { return i<j; }

struct myclass {
  bool operator() (int i,int j) { return i<j; }
} myobj;

int main () {
  int myints[] = {3,7,2,5,6,4,9};

  // using default comparison:
  cout << "The smallest element is " << *min_element(myints,myints+7) << endl;
  cout << "The largest element is " << *max_element(myints,myints+7) << endl;

  // using function myfn as comp:
  cout << "The smallest element is " << *min_element(myints,myints+7,myfn) << endl;
  cout << "The largest element is " << *max_element(myints,myints+7,myfn) << endl;

  // using object myobj as comp:
  cout << "The smallest element is " << *min_element(myints,myints+7,myobj) << endl; cout << "The largest element is " << *max_element(myints,myints+7,myobj) << endl;

  return 0;
}
5、next_permutation:返回的是(序列中所有元素組合中的)一個
原型:
template <class BidirectionalIterator>
  bool next_permutation (BidirectionalIterator first,
                         BidirectionalIterator last );

template <class BidirectionalIterator, class Compare>
  bool next_permutation (BidirectionalIterator first,
                         BidirectionalIterator last, Compare comp);
示例:
// next_permutation
#include <iostream>
#include <algorithm>
using namespace std;

int main () {
  int myints[] = {1,2,3};

  cout << "The 3! possible permutations with 3 elements:\n";

  sort (myints,myints+3);

  do {
    cout << myints[0] << " " << myints[1] << " " << myints[2] << endl;
  } while ( next_permutation (myints,myints+3) );

  return 0;
}
6、prev_permutation:和next_permutation功能類似,返回的是序列中(所有元素)前一個組合
原型:
<algorithm>
template <class BidirectionalIterator>
  bool prev_permutation (BidirectionalIterator first,
                         BidirectionalIterator last );

template <class BidirectionalIterator, class Compare>
  bool prev_permutation (BidirectionalIterator first,
                         BidirectionalIterator last, Compare comp);
示例:
// prev_permutation
#include <iostream>
#include <algorithm>
using namespace std;

int main () {
  int myints[] = {1,2,3};

  cout << "The 3! possible permutations with 3 elements:\n";

  sort (myints,myints+3);
  reverse (myints,myints+3);

  do {
    cout << myints[0] << " " << myints[1] << " " << myints[2] << endl;
  } while ( prev_permutation (myints,myints+3) );

  return 0;
}
7、lexicographical_compare:字典比較(針對的是兩個序列,返回的是布爾值)
原型:
template <class InputIterator1, class InputIterator2>
bool lexicographical_compare ( InputIterator1 first1, InputIterator1 last1,
                                 InputIterator2 first2, InputIterator2 last2 );
template <class InputIterator1, class InputIterator2, class Compare>
  bool lexicographical_compare ( InputIterator1 first1, InputIterator1 last1,
                                 InputIterator2 first2, InputIterator2 last2,
                                 Compare comp );
示例:// lexicographical_compare example #include <iostream> #include <algorithm> #include <cctype> using namespace std; // a case-insensitive comparison function: bool mycomp (char c1, char c2) { return tolower(c1)<tolower(c2); } int main () { char first[]="Apple"; // 5 letters char second[]="apartment"; // 9 letters cout << "Using default comparison (operator<): "; if (lexicographical_compare(first,first+5,second,second+9)) cout << first << " is less than " << second << endl; else if (lexicographical_compare(second,second+9,first,first+5)) cout << first << " is greater than " << second << endl; else cout << first << " and " << second << " are equivalent\n"; cout << "Using mycomp as comparison object: "; if (lexicographical_compare(first,first+5,second,second+9,mycomp)) cout << first << " is less than " << second << endl; else if (lexicographical_compare(second,second+9,first,first+5,mycomp)) cout << first << " is greater than " << second << endl; else cout << first << " and " << second << " are equivalent\n"; return 0; }

 

posted on 2012-01-08 16:54 Benjamin 閱讀(891) 評論(1)  編輯 收藏 引用 所屬分類: 泛型編程

評論

# re: STL算法(Algorithms):極值[未登錄]  回復  更多評論   

非淡泊無以明志
2012-01-09 13:26 | 春秋十二月
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            久久精品国产综合| 亚洲电影免费在线 | 亚洲激情小视频| 久久亚洲精品一区| 免费高清在线一区| 亚洲国产精品va在线观看黑人| 欧美成人精品激情在线观看| 亚洲黄色av| 在线亚洲一区二区| 欧美一区国产二区| 欧美国产成人精品| 国产精品久久久久久久久久ktv| 国产精品视频内| 一区二区在线观看av| 亚洲精品自在久久| 欧美在线视频免费播放| 欧美电影打屁股sp| 中日韩美女免费视频网站在线观看| 亚洲自拍偷拍网址| 麻豆亚洲精品| 国产精品一区三区| 亚洲国产欧美一区二区三区丁香婷| 亚洲免费高清| 久久久国产精品一区| 亚洲欧美精品一区| 六月天综合网| 在线视频日本亚洲性| 亚洲在线黄色| 欧美寡妇偷汉性猛交| 国产日韩亚洲欧美精品| 亚洲激情六月丁香| 欧美有码在线视频| 99这里有精品| 欧美国产欧美亚洲国产日韩mv天天看完整 | 欧美国产大片| 销魂美女一区二区三区视频在线| 免费看黄裸体一级大秀欧美| 国产欧美日韩在线视频| 99精品视频一区二区三区| 久久久女女女女999久久| 一区二区日韩伦理片| 欧美99久久| 激情欧美日韩一区| 久久久久久久久久看片| 中文国产成人精品久久一| 欧美国产精品中文字幕| 亚洲东热激情| 可以免费看不卡的av网站| 午夜精彩国产免费不卡不顿大片| 欧美色图首页| 亚洲深夜av| 亚洲乱码久久| 欧美区视频在线观看| 一区二区三区免费观看| 欧美成人精品一区| 亚洲片在线观看| 亚洲国产精品123| 欧美1区2区视频| 亚洲欧洲一区二区天堂久久| 欧美a级片网站| 麻豆国产精品777777在线| 亚洲成在线观看| 欧美激情视频给我| 欧美国产日产韩国视频| 日韩视频精品| 99re66热这里只有精品4| 久久中文在线| 91久久视频| 精品福利电影| 欧美高清影院| 欧美激情一区二区三区在线视频观看 | 午夜激情亚洲| 亚洲人成久久| 欧美日韩天堂| 亚洲制服少妇| 欧美一级大片在线免费观看| 国产一区在线视频| 欧美成人伊人久久综合网| 欧美成人精品激情在线观看 | 韩国av一区二区三区| 久久久天天操| 免费看av成人| 午夜在线不卡| 久久久久久夜精品精品免费| 在线精品视频在线观看高清 | 噜噜噜久久亚洲精品国产品小说| 久久久久久久精| 日韩一区二区高清| 亚洲欧美变态国产另类| 亚洲电影自拍| 亚洲一区二区三区四区在线观看| 国内精品久久久久影院薰衣草| 美日韩精品免费观看视频| 欧美国产在线观看| 欧美在线不卡| 欧美精品综合| 久久久久久亚洲综合影院红桃| 欧美成人国产一区二区| 欧美伊人久久久久久午夜久久久久| 久久免费高清视频| 亚洲影视综合| 欧美成人在线网站| 久久精品亚洲精品国产欧美kt∨| 欧美国产日韩一区二区| 久久久亚洲人| 国产精品三上| 99精品国产99久久久久久福利| 伊甸园精品99久久久久久| 亚洲一区二区av电影| 日韩视频在线你懂得| 欧美在线观看天堂一区二区三区| 在线亚洲欧美专区二区| 久久综合五月天婷婷伊人| 性久久久久久久久久久久| 欧美激情1区2区| 美女国产一区| 国产午夜精品美女毛片视频| 一本久久精品一区二区| 亚洲九九爱视频| 久久偷窥视频| 久久一区精品| 国产色婷婷国产综合在线理论片a| 亚洲精品视频在线播放| 亚洲日本电影在线| 女同性一区二区三区人了人一 | 模特精品裸拍一区| 国产一区二区三区久久久| 亚洲自拍三区| 欧美一级视频免费在线观看| 欧美三级网址| 一本不卡影院| 亚洲三级国产| 亚洲黄色高清| 欧美成人按摩| 欧美国产日本在线| 一区精品在线播放| 久久资源在线| 欧美激情网站在线观看| 亚洲第一区中文99精品| 久久这里有精品视频| 欧美成人69av| 亚洲精品久久| 欧美日韩国产三区| 一本色道久久综合| 亚洲一区二区在| 国产精品一区二区久久国产| 亚洲欧美中文字幕| 久久米奇亚洲| 亚洲国产免费看| 欧美精品电影| 亚洲视频福利| 久久久欧美一区二区| 在线观看亚洲精品视频| 欧美国产日本韩| 亚洲视频一区在线| 久久五月天婷婷| 一本久道久久综合婷婷鲸鱼| 国产精品久久一卡二卡| 欧美一区二区私人影院日本| 欧美1区3d| 中文在线一区| 国产一区二区无遮挡| 欧美超级免费视 在线| 在线视频一区观看| 久久夜色精品一区| 99日韩精品| 国产日韩欧美亚洲一区| 美日韩精品视频| 一本一本久久a久久精品综合麻豆| 欧美一区二区三区另类| 在线电影院国产精品| 国产精品www色诱视频| 久久先锋影音| 中文成人激情娱乐网| 欧美 日韩 国产一区二区在线视频| 亚洲美女黄网| 精品二区视频| 国产精品丝袜xxxxxxx| 裸体一区二区| 午夜精品久久| 亚洲久久一区| 免费短视频成人日韩| 亚洲与欧洲av电影| 91久久在线| 韩国精品在线观看| 国产精品久久久久久久app| 玖玖玖国产精品| 亚洲欧美日韩一区二区三区在线| 亚洲福利视频三区| 久久亚洲影院| 欧美自拍偷拍| 亚洲一二三区精品| 亚洲人精品午夜在线观看| 国产香蕉97碰碰久久人人| 欧美日韩在线播放一区| 欧美成人r级一区二区三区| 久久国产免费看| 亚洲欧美一区二区激情| 国产精品99久久久久久人| 亚洲精品乱码久久久久|