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

Benjamin

靜以修身,儉以養(yǎng)德,非澹薄無以明志,非寧靜無以致遠(yuǎn)。
隨筆 - 398, 文章 - 0, 評論 - 196, 引用 - 0
數(shù)據(jù)加載中……

STL算法(Algorithms):極值

1、min:返回兩個兩個參數(shù)中的最小值
原型: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:返回兩個參數(shù)中的大值
原型:
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:返回(迭代器)指定范圍內(nèi)的最小元素
原型:
// 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:返回(迭代器)指定范圍內(nèi)的最小元素
原型:
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 閱讀(879) 評論(1)  編輯 收藏 引用 所屬分類: 泛型編程

評論

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

非淡泊無以明志
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>
            亚洲一区二区动漫| 欧美成人精品1314www| 亚洲精品欧美日韩专区| 你懂的网址国产 欧美| 91久久线看在观草草青青| 免费在线观看成人av| 欧美gay视频| 一区二区电影免费观看| 亚洲天堂网在线观看| 国产伦一区二区三区色一情| 久久久久久电影| 久久久久99| 日韩视频在线免费观看| 亚洲先锋成人| 极品少妇一区二区三区精品视频 | 欧美激情成人在线| 一本高清dvd不卡在线观看| 在线一区二区三区四区五区| 国产情人节一区| 欧美不卡福利| 欧美午夜在线一二页| 久久影视精品| 欧美日本韩国一区二区三区| 欧美在线综合| 欧美精品一区二区在线播放| 性欧美大战久久久久久久免费观看| 欧美亚洲网站| 中日韩在线视频| 久久久久久亚洲精品杨幂换脸 | 激情综合久久| 亚洲毛片av在线| 国产在线观看一区| 亚洲精品乱码视频| 国产偷国产偷精品高清尤物| 亚洲精品视频免费观看| 国产一区二区三区四区在线观看| 亚洲黄色免费网站| 国产原创一区二区| 亚洲图片在线| 亚洲美女毛片| 久久影视三级福利片| 香蕉久久精品日日躁夜夜躁| 欧美日韩另类在线| 亚洲第一中文字幕| 国产一区二区视频在线观看| 一本色道久久综合狠狠躁的推荐| 亚洲福利视频一区| 久久成人精品电影| 久久国产精品99久久久久久老狼| 欧美午夜视频在线观看| 亚洲人成网站影音先锋播放| 亚洲第一毛片| 久久精品91久久久久久再现| 久久精品国产第一区二区三区| 欧美日韩三级一区二区| 亚洲精品黄色| 亚洲美女色禁图| 你懂的一区二区| 久久米奇亚洲| 久久久久欧美精品| 国产一区视频网站| 西西裸体人体做爰大胆久久久| 亚洲免费小视频| 欧美三级乱码| 一区二区三区免费观看| 在线亚洲欧美| 欧美色一级片| 一区二区三区|亚洲午夜| 99爱精品视频| 欧美日韩一区二区三区| 日韩午夜在线| 小处雏高清一区二区三区| 国产精品国产成人国产三级| 亚洲一本大道在线| 久久av红桃一区二区小说| 国产农村妇女毛片精品久久麻豆 | 午夜精品视频在线| 久久精品国产99精品国产亚洲性色| 国产精品亚洲激情| 欧美一区二区三区日韩| 久久久亚洲影院你懂的| 亚洲福利视频三区| 欧美日韩国产麻豆| 亚洲欧美电影院| 久久久美女艺术照精彩视频福利播放 | 新67194成人永久网站| 久久精品亚洲精品国产欧美kt∨| 国内精品久久久久久久影视蜜臀 | 欧美一区二区精品| 蜜乳av另类精品一区二区| 亚洲人成毛片在线播放女女| 欧美色另类天堂2015| 欧美中文在线观看| 亚洲黄色在线看| 香蕉久久一区二区不卡无毒影院| 极品少妇一区二区| 欧美日韩在线播放一区二区| 性色av一区二区三区在线观看| 麻豆av一区二区三区| 999在线观看精品免费不卡网站| 国产精品高潮在线| 久久网站免费| 中文一区字幕| 免费亚洲一区二区| 亚洲欧美日韩国产综合在线| 在线观看欧美日韩国产| 欧美日韩在线播| 久久五月激情| 亚洲在线1234| 亚洲国产欧美国产综合一区| 欧美怡红院视频| 99ri日韩精品视频| 在线免费观看欧美| 国产精品色网| 欧美日韩99| 久久亚洲精品欧美| 午夜视频在线观看一区| 99re这里只有精品6| 美玉足脚交一区二区三区图片| 亚洲女人天堂成人av在线| 亚洲三级免费| 在线国产日韩| 国产一区亚洲一区| 国产午夜亚洲精品理论片色戒| 欧美日韩在线不卡| 欧美黄色免费网站| 久久综合五月| 久久精品首页| 欧美在线免费看| 亚洲一区二区三区中文字幕在线| 亚洲精品乱码久久久久久蜜桃麻豆| 你懂的国产精品| 久久九九免费| 久久精品一区中文字幕| 欧美亚洲综合久久| 欧美一区二区三区久久精品| 亚洲午夜三级在线| 一区二区三区免费观看| 99亚洲视频| 亚洲免费精品| 99精品热视频| 一区二区三区日韩| 中文在线不卡视频| 亚洲桃色在线一区| 亚洲欧美日韩精品久久亚洲区 | 欧美一级视频免费在线观看| 亚洲综合久久久久| 亚洲综合精品| 欧美中文字幕在线| 久久嫩草精品久久久久| 久热精品视频| 欧美激情按摩| 亚洲第一级黄色片| 亚洲精选国产| 99视频精品免费观看| 一区二区三区四区五区视频| 亚洲午夜电影在线观看| 亚洲欧美日韩在线综合| 欧美在线视频a| 久久亚洲一区| 欧美日韩福利| 国产日韩一区二区三区| 狠狠色噜噜狠狠色综合久| 亚洲国产精品黑人久久久 | 国产日韩欧美在线看| 激情六月综合| 日韩视频免费大全中文字幕| 亚洲直播在线一区| 裸体歌舞表演一区二区| 亚洲国产精品久久久久秋霞影院| 一区二区免费看| 午夜精品久久久久久久久久久久久| 久久久国产亚洲精品| 欧美精品日韩一区| 国产欧美日韩在线观看| 亚洲国产一区二区三区a毛片| 亚洲桃花岛网站| 麻豆精品网站| 一区二区三区视频免费在线观看| 久久av一区二区三区漫画| 欧美阿v一级看视频| 国产精品实拍| 亚洲精品久久久久久下一站 | 国产一区二区久久精品| 亚洲精品日韩综合观看成人91| 亚洲免费一级电影| 欧美激情国产日韩精品一区18| 亚洲午夜国产一区99re久久 | 一本一本a久久| 久久久亚洲国产美女国产盗摄| 欧美午夜剧场| 最近看过的日韩成人| 久久成人国产| 亚洲精品国精品久久99热| 欧美在线三区| 国产女主播在线一区二区| av成人免费观看| 欧美ab在线视频| 欧美在线视频一区| 国产精品久久久久久久7电影 |