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

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>
            欧美一区中文字幕| 噜噜爱69成人精品| 国产精品日韩欧美一区二区| 亚洲伦理在线观看| 一本色道久久88综合亚洲精品ⅰ| 欧美日韩的一区二区| 亚洲午夜视频在线| 亚洲欧美中文另类| 1024亚洲| 日韩视频一区二区三区在线播放免费观看 | 亚洲精品在线观看视频| 欧美丰满高潮xxxx喷水动漫| 免费精品视频| 亚洲午夜激情网站| 性做久久久久久久免费看| 国内精品久久久久伊人av| 欧美阿v一级看视频| 欧美区日韩区| 欧美在线影院| 女人香蕉久久**毛片精品| 亚洲视频欧美视频| 午夜精品福利电影| 亚洲国产精品第一区二区| 亚洲免费观看视频| 国产一区二区你懂的| 欧美福利一区| 国产精品推荐精品| 免费成人黄色| 国产精品免费视频xxxx| 裸体歌舞表演一区二区| 欧美三级视频在线| 久久偷看各类wc女厕嘘嘘偷窃| 欧美国产日产韩国视频| 欧美在线一二三| 欧美福利小视频| 久久精品在这里| 欧美日本高清视频| 久久三级视频| 国产精品乱人伦一区二区 | 在线天堂一区av电影| 久久爱另类一区二区小说| 日韩午夜av| 久久天堂精品| 久久精品视频免费播放| 欧美精品三级日韩久久| 久久久久综合| 国产精品一区久久| 亚洲精品美女免费| 在线欧美视频| 久久国产精品色婷婷| 亚洲女优在线| 欧美人与性动交a欧美精品| 巨胸喷奶水www久久久免费动漫| 欧美日韩一区二| 最新高清无码专区| 亚洲国产91| 久久久久国产一区二区| 久久久久国产精品麻豆ai换脸| 欧美视频一区二区| 日韩网站在线看片你懂的| 亚洲区欧美区| 你懂的视频欧美| 亚洲国产高清在线观看视频| 亚洲国产mv| 女女同性精品视频| 欧美高清在线一区二区| 亚洲国产精品专区久久| 久久久爽爽爽美女图片| 男人的天堂成人在线| 亚洲成人原创| 欧美va亚洲va日韩∨a综合色| 欧美成人国产va精品日本一级| 狠狠色综合网站久久久久久久| 午夜精品一区二区三区在线| 欧美亚洲色图校园春色| 国产日韩欧美高清| 久久九九全国免费精品观看| 久久中文字幕一区| 亚洲第一天堂无码专区| 欧美成人精品在线播放| 亚洲精品小视频| 一区二区欧美在线| 国产精品国产自产拍高清av| 亚洲影视综合| 美女尤物久久精品| 亚洲精品视频在线播放| 欧美日韩亚洲高清| 午夜精品久久久久久久久久久| 久久国产精品久久久久久电车| 国产亚洲一级| 免费人成精品欧美精品| 99在线|亚洲一区二区| 欧美一区网站| 亚洲欧洲精品一区二区| 欧美日韩中文字幕日韩欧美| 午夜国产精品影院在线观看| 免费永久网站黄欧美| 一区二区成人精品 | 欧美日韩国产成人在线观看| 亚洲精品欧美专区| 欧美在线综合| 9久re热视频在线精品| 国产女人精品视频| 麻豆精品传媒视频| 中文成人激情娱乐网| 久久综合成人精品亚洲另类欧美 | 欧美四级在线| 久久精品一区二区三区四区 | 亚洲一区在线免费| 欧美高清视频免费观看| 亚洲欧美日韩另类| 最新日韩精品| 国产一区二区电影在线观看| 欧美激情一区二区三区全黄| 欧美在线视频导航| 一本色道久久加勒比88综合| 女仆av观看一区| 久久成人国产| 亚洲一区二区三区在线看| 亚洲国产精品久久久久秋霞不卡| 欧美午夜三级| 欧美精品一区二区三区久久久竹菊 | 久久国产一区二区| 在线亚洲精品| 最新日韩欧美| 精品动漫3d一区二区三区| 国产精品青草久久| 欧美日韩在线一区二区| 免费一级欧美片在线播放| 欧美影院一区| 午夜精品久久久久久久久久久久久| 亚洲人成亚洲人成在线观看图片| 免费观看国产成人| 久久蜜桃资源一区二区老牛| 午夜精品视频在线观看| 亚洲伊人久久综合| 一本久久综合亚洲鲁鲁| 亚洲毛片在线观看.| 亚洲精品黄色| 最新日韩中文字幕| 91久久精品国产91性色tv| 亚洲国产一区二区a毛片| 激情综合电影网| 在线日本欧美| 亚洲黄色一区| 亚洲国内精品在线| 亚洲国内自拍| 99riav久久精品riav| 亚洲精品欧美| 一区二区日韩欧美| 亚洲一区二区在线播放| 亚洲午夜久久久久久久久电影院 | 黄色成人免费观看| 一区二区三区在线观看视频| 一区二区亚洲精品国产| 亚洲激情社区| aa级大片欧美| 亚洲欧美精品在线观看| 欧美一区二区在线播放| 久久综合伊人77777| 嫩模写真一区二区三区三州| 女仆av观看一区| 亚洲精品欧美| 亚洲精品美女| 亚洲一区精品视频| 久久久国产成人精品| 欧美不卡视频| 国产精品黄色在线观看| 狠狠色狠色综合曰曰| 亚洲激情黄色| 亚洲欧美一区在线| 久久精品一区蜜桃臀影院| 亚洲成在线观看| 一区二区三区欧美视频| 久久精品国产免费看久久精品 | 一区二区三区四区五区精品| 亚洲综合日韩中文字幕v在线| 久久精品综合网| 欧美精品日韩综合在线| 国产性猛交xxxx免费看久久| 亚洲国产日韩欧美| 亚洲男女毛片无遮挡| 免费日韩视频| 亚洲一区二区精品在线| 玖玖玖免费嫩草在线影院一区| 欧美日韩免费观看一区| 好吊妞**欧美| 亚洲午夜久久久久久久久电影网| 久久久久久9| 亚洲深夜福利在线| 牛夜精品久久久久久久99黑人 | 国产精品毛片a∨一区二区三区|国 | 亚洲丶国产丶欧美一区二区三区 | 亚洲第一区在线观看| 亚洲欧美资源在线| 欧美激情va永久在线播放| 亚洲欧美成人精品| 欧美日韩国产欧美日美国产精品| 国产在线乱码一区二区三区| 一区二区三区www|