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

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 閱讀(897) 評論(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>
            久久久精品动漫| 亚洲一区三区视频在线观看| 久久夜色精品一区| 亚洲一区二区三区久久| 国产精品成人一区二区艾草| 亚洲视频综合在线| 一区二区三区视频在线观看 | 一本色道久久综合亚洲二区三区 | 亚洲欧美三级伦理| 国产精品久久久免费| 亚洲欧美国产不卡| 欧美一区午夜视频在线观看| 国内精品视频久久| 免费成人网www| 欧美国产另类| 午夜视黄欧洲亚洲| 午夜天堂精品久久久久 | 欧美日本免费| 亚洲制服丝袜在线| 午夜亚洲伦理| 亚洲国产综合91精品麻豆| 亚洲激情中文1区| 欧美国产日本| 亚洲欧美视频在线| 久久久久国产精品人| 亚洲美女福利视频网站| 国产精品久久| 免费亚洲网站| 欧美性大战久久久久久久| 欧美一级视频一区二区| 亚洲国产精品第一区二区| 欧美日韩在线视频一区二区| 欧美伊人久久大香线蕉综合69| 久久久噜噜噜久久| 在线性视频日韩欧美| 久久av一区二区三区| 亚洲精选视频在线| 欧美亚洲一区三区| 亚洲美女色禁图| 欧美综合国产精品久久丁香| 99国产精品视频免费观看| 欧美一区二区三区免费观看视频| 亚洲精品小视频| 欧美一级久久久| 亚洲网址在线| 免费观看成人www动漫视频| 欧美中文字幕| 欧美日韩亚洲高清一区二区| 欧美凹凸一区二区三区视频| 国产精品推荐精品| 亚洲国产高清高潮精品美女| 国产日韩欧美精品在线| 99精品热视频| 99精品视频免费全部在线| 久久久久久久尹人综合网亚洲| 亚洲综合视频网| 欧美日韩国产小视频| 你懂的一区二区| 激情成人亚洲| 久久精品一级爱片| 久久大逼视频| 国产欧美日韩精品一区| 亚洲作爱视频| 一区二区三区视频免费在线观看| 美女福利精品视频| 欧美阿v一级看视频| 亚洲大黄网站| 久久久久免费视频| 久久久青草青青国产亚洲免观| 国产精品一页| 亚洲愉拍自拍另类高清精品| 亚洲天堂av图片| 欧美日韩日日夜夜| 一区二区欧美日韩| 亚洲综合三区| 国产精品久久久久aaaa九色| 一区二区三区国产精华| 亚洲午夜一区二区三区| 欧美午夜不卡视频| 中文成人激情娱乐网| 国产精品美女午夜av| 亚洲一区二区免费| 午夜在线观看免费一区| 国产精品无码永久免费888| 亚洲色诱最新| 久久九九久久九九| 一区二区三区在线免费观看| 浪潮色综合久久天堂| 欧美激情一区二区三区高清视频 | 国内精品亚洲| 久久婷婷丁香| 亚洲第一视频网站| 一本久久综合亚洲鲁鲁五月天| 欧美午夜在线一二页| 亚洲欧美色一区| 久久亚洲精品中文字幕冲田杏梨| 亚洲黄色视屏| 欧美日韩一区在线播放| 亚洲综合精品| 欧美国产日产韩国视频| 亚洲一区二区视频| 国产一区二区三区久久久| 美女黄色成人网| 99亚洲视频| 久久全国免费视频| 亚洲乱码国产乱码精品精 | 小处雏高清一区二区三区| 可以免费看不卡的av网站| 日韩一级片网址| 国产美女高潮久久白浆| 麻豆久久婷婷| 午夜亚洲精品| 亚洲精品一区在线观看| 久久久精品国产一区二区三区| 亚洲美女毛片| 国产在线麻豆精品观看| 欧美精品v日韩精品v国产精品| 亚洲女人天堂成人av在线| 亚洲第一中文字幕在线观看| 亚洲欧美文学| 日韩天堂av| 伊人蜜桃色噜噜激情综合| 欧美日韩在线视频首页| 老色鬼精品视频在线观看播放| 亚洲一区成人| 亚洲精品亚洲人成人网| 噜噜噜91成人网| 久久成人一区二区| 亚洲男同1069视频| 日韩一区二区免费看| 国产一区清纯| 国产伦精品一区二区三区高清 | 宅男噜噜噜66一区二区| 亚洲高清成人| 欧美成人高清视频| 欧美大片专区| 久久成人免费电影| 亚洲综合日韩中文字幕v在线| 亚洲黄色免费| 亚洲第一区色| 欧美电影在线观看| 久久尤物电影视频在线观看| 欧美一区二区在线免费播放| 中文亚洲欧美| 亚洲影院免费观看| 亚洲伦理一区| 一本色道久久88综合日韩精品| 亚洲欧美成人精品| 亚洲香蕉成视频在线观看| 亚洲精品免费在线观看| 亚洲精品视频在线观看免费| 在线精品观看| 亚洲成人在线| 亚洲欧洲精品成人久久奇米网 | 国产精品爱久久久久久久| 欧美日韩国产色站一区二区三区 | 在线综合视频| 亚洲在线网站| 久久精品亚洲一区二区| 久久av在线| 欧美凹凸一区二区三区视频| 欧美aaa级| 欧美日韩综合在线| 国产精品久久久久久亚洲调教| 国产伦精品一区二区三| 韩国三级电影久久久久久| 国产综合欧美| 亚洲人成毛片在线播放| 99亚洲精品| 香蕉久久a毛片| 久久一区免费| 欧美国产三级| 一区二区三欧美| 久久成人精品无人区| 欧美成人精品一区| 欧美午夜一区二区三区免费大片| 国产欧美大片| 亚洲欧洲日产国产网站| 亚洲一品av免费观看| 久久疯狂做爰流白浆xx| 欧美激情一区二区三区成人| 日韩视频精品在线观看| 欧美伊人久久| 免费亚洲电影在线| 夜夜嗨av一区二区三区网页| 欧美一级视频精品观看| 欧美风情在线| 国产欧美成人| 一区二区高清在线| 久久精品成人一区二区三区蜜臀 | 欧美激情一区二区三区| 欧美精品日韩综合在线| 国产精品美腿一区在线看| 日韩视频免费在线| 欧美成人福利视频| 欧美激情亚洲一区| 国产主播一区| 亚洲综合好骚| 亚洲人成高清| 久久久久免费观看|