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

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 閱讀(894) 評論(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>
            在线亚洲一区二区| 久久精品道一区二区三区| 免费成人高清| 久久综合伊人77777| 黄色欧美成人| 欧美高清视频免费观看| 玖玖视频精品| 亚洲精品一区二区在线观看| 欧美国产一区视频在线观看 | 亚洲毛片在线免费观看| 欧美视频中文字幕在线| 欧美激情无毛| 正在播放亚洲一区| 国产精品免费区二区三区观看| 亚洲图片在线观看| 亚洲在线一区二区| 国产欧美日韩免费看aⅴ视频| 午夜一级在线看亚洲| 欧美在线啊v一区| 一区二区三区国产盗摄| 亚洲欧美一区二区在线观看| 久久久久久久久久久一区| 伊人伊人伊人久久| 国产精品综合不卡av| 制服丝袜激情欧洲亚洲| 在线国产精品播放| 久久久女女女女999久久| 永久555www成人免费| 另类成人小视频在线| 午夜久久一区| 欧美日韩亚洲一区二区三区| 亚洲欧洲精品一区二区三区| 欧美一级久久| 又紧又大又爽精品一区二区| 欧美一区二区福利在线| 亚洲国产精品成人综合| aa国产精品| 在线观看不卡av| 一区二区三区回区在观看免费视频| 国产日韩视频| 最新国产乱人伦偷精品免费网站| 国产伦精品一区二区三区免费| 欧美国产日韩xxxxx| 国产精品一区二区在线观看| 欧美激情中文不卡| 国产喷白浆一区二区三区 | 欧美色图首页| 久久综合免费视频影院| 国产精品国色综合久久| 欧美激情亚洲自拍| 激情欧美日韩一区| 亚洲欧美一区二区原创| 亚洲性人人天天夜夜摸| 免费亚洲电影在线观看| 久久国产一二区| 欧美日韩中文字幕在线| 亚洲欧洲日本一区二区三区| 在线国产欧美| 欧美影院精品一区| 久久精品一区二区三区四区| 欧美三级视频在线播放| 亚洲国产一区二区a毛片| 136国产福利精品导航| 久久成人综合网| 欧美一区二区三区四区在线观看地址 | 亚洲精品一区二区网址| 久久躁狠狠躁夜夜爽| 久久精品国产亚洲aⅴ| 国产精品视频区| 在线中文字幕不卡| 亚洲影音先锋| 国产精品久久久久高潮| 亚洲小说欧美另类社区| 一区二区三区偷拍| 欧美视频在线观看免费| 一本久久青青| 亚洲欧美日韩综合国产aⅴ| 欧美丝袜一区二区| 中日韩美女免费视频网址在线观看| 亚洲视频每日更新| 国产精品白丝av嫩草影院| 亚洲视频一区二区在线观看| 亚洲免费一在线| 国产精品日韩在线| 性8sex亚洲区入口| 久久久久这里只有精品| 尤物精品国产第一福利三区| 男女av一区三区二区色多| 亚洲精品中文字幕在线| 亚洲自拍16p| 国产毛片精品国产一区二区三区| 亚洲一二三四久久| 久久人人97超碰精品888| 亚洲欧洲精品一区二区| 欧美三级在线视频| 性一交一乱一区二区洋洋av| 久久一二三四| 日韩视频精品| 国产精品网站在线播放| 欧美一区二区网站| 亚洲电影免费观看高清完整版在线观看| 日韩亚洲在线观看| 国产欧美亚洲视频| 久久综合伊人77777麻豆| 日韩午夜视频在线观看| 久久手机免费观看| 亚洲美女啪啪| 国产亚洲在线观看| 欧美日韩人人澡狠狠躁视频| 久久成人av少妇免费| 亚洲精品在线电影| 久久亚洲午夜电影| 亚洲天堂av电影| 国产一区二区三区在线播放免费观看| 欧美jizz19性欧美| 午夜精品久久久久久久99黑人| 欧美激情在线免费观看| 久久精彩免费视频| 一区二区三区欧美在线| 一区二区三区在线观看国产| 欧美网站在线观看| 久久综合网hezyo| 亚洲一区二区视频在线| 亚洲欧洲偷拍精品| 美女国内精品自产拍在线播放| 亚洲免费网址| 亚洲免费观看| 伊人久久亚洲影院| 国产视频欧美视频| 欧美午夜一区二区| 欧美高清视频一区二区| 久久av红桃一区二区小说| 艳女tv在线观看国产一区| 亚洲国产欧美一区二区三区丁香婷| 欧美综合国产精品久久丁香| 亚洲一级电影| 在线综合亚洲| 99精品国产一区二区青青牛奶 | 久久精品人人做人人爽| 亚洲在线免费| 亚洲精品在线观| 亚洲激情成人在线| 欧美黄污视频| 欧美成人r级一区二区三区| 久久精品综合网| 羞羞漫画18久久大片| 亚洲欧美成人一区二区三区| 在线午夜精品| 亚洲精品一区在线观看| 亚洲国产专区校园欧美| 亚洲国产欧美一区| 亚洲国产精品久久久久秋霞影院| 国产午夜久久| 国产主播喷水一区二区| 国产日韩欧美高清| 狠狠色丁香婷婷综合影院| 激情久久久久久久| 曰本成人黄色| 91久久午夜| 亚洲精品免费观看| 亚洲精选视频在线| 妖精视频成人观看www| 亚洲图片欧洲图片av| 亚洲一区二区3| 欧美一级片一区| 久久久视频精品| 欧美国产日韩一区二区| 亚洲精品影院| 亚洲一区影音先锋| 久久国产精品99精品国产| 久久久91精品| 欧美精品一卡| 国产精品色婷婷久久58| 国产有码在线一区二区视频| 在线免费观看日韩欧美| 中日韩在线视频| 午夜欧美大片免费观看| 另类av导航| 99国产精品99久久久久久粉嫩| 亚洲影院高清在线| 久久久人成影片一区二区三区 | 久久久最新网址| 欧美连裤袜在线视频| 国产精品女同互慰在线看| 永久免费精品影视网站| 在线亚洲欧美| 久久性天堂网| 一区二区三区高清视频在线观看 | 欧美α欧美αv大片| 亚洲精品美女91| 欧美一区二区三区四区高清| 欧美成人嫩草网站| 国产喷白浆一区二区三区| 亚洲人成网在线播放| 欧美一区二区精品| 亚洲理论电影网| 久久av免费一区| 国产精品久久久久久av福利软件 | 国产美女精品在线| 亚洲精选久久|