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

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>
            欧美高清在线| 亚洲精品一二| 欧美岛国激情| 免费一区视频| 免费一级欧美在线大片| 美国成人毛片| 欧美日韩另类综合| 国产精品永久免费在线| 精品成人在线视频| 99国产精品私拍| 亚洲欧美制服另类日韩| 久久久国产午夜精品| 欧美婷婷久久| 一级成人国产| 欧美在线视频免费观看| 毛片基地黄久久久久久天堂| 欧美精品v日韩精品v韩国精品v| 欧美日韩免费高清| 国产偷久久久精品专区| 亚洲福利视频三区| 亚洲在线一区二区| 麻豆成人在线播放| 一区二区三区精品国产| 久久漫画官网| 国产精品日本| 99国产欧美久久久精品| 久久精品亚洲一区二区| 亚洲精品一区二区三区av| 欧美一区二区成人| 欧美日韩一区二区视频在线观看 | 久久高清免费观看| 亚洲国产成人av好男人在线观看| 亚洲国产精品一区| 久久国产精品99精品国产| 欧美视频日韩视频| 亚洲国产综合在线看不卡| 欧美一区二区在线视频| 亚洲人成亚洲人成在线观看图片| 欧美一区二区性| 国产精品久久久久9999高清| 亚洲美女福利视频网站| 久久综合一区二区三区| 亚洲欧美日韩国产中文在线| 欧美欧美午夜aⅴ在线观看| 影音先锋亚洲电影| 久久精品九九| 亚洲欧美电影在线观看| 欧美视频国产精品| 99精品久久免费看蜜臀剧情介绍| 欧美 日韩 国产在线 | 亚洲国产成人av| 久久久精品国产免大香伊| 国产精品视频网址| 亚洲资源在线观看| 一本色道久久99精品综合| 欧美好吊妞视频| 亚洲精品国产精品国自产观看浪潮 | 欧美高清视频免费观看| 国模套图日韩精品一区二区| 午夜精品久久久久久久白皮肤| 亚洲免费大片| 欧美色欧美亚洲另类二区 | 亚洲黄色免费网站| 午夜一区二区三区在线观看| 国产精品成人一区二区网站软件| 亚洲视频免费观看| 一区二区不卡在线视频 午夜欧美不卡在| 麻豆亚洲精品| 日韩亚洲欧美成人一区| 亚洲开发第一视频在线播放| 欧美日韩国产一区二区三区| 一区二区国产日产| 亚洲综合日韩在线| 国产三级精品三级| 久久综合国产精品台湾中文娱乐网| 欧美中文字幕视频| 亚洲高清123| 日韩视频免费| 国产农村妇女毛片精品久久莱园子| 久久精品导航| 欧美大成色www永久网站婷| 在线亚洲欧美专区二区| 亚洲在线播放| 136国产福利精品导航网址| 亚洲国产精品t66y| 国产精品国产自产拍高清av| 久久久久se| 欧美日韩国产免费| 欧美中文字幕在线播放| 欧美波霸影院| 午夜在线一区二区| 蜜桃久久av| 欧美影院一区| 欧美成人激情在线| 欧美一级在线视频| 久久久亚洲一区| 一区二区三区国产精华| 欧美一区二区在线视频| 日韩视频三区| 久久狠狠亚洲综合| 一本色道久久加勒比精品| 小黄鸭视频精品导航| 亚洲精品一区二区三区在线观看| 在线中文字幕一区| 亚洲国产欧美一区二区三区久久| 亚洲视频狠狠| 日韩一级精品| 久久亚洲一区二区三区四区| 午夜精品美女自拍福到在线| 欧美成黄导航| 麻豆精品一区二区综合av| 国产精品久久7| 亚洲高清一二三区| 韩国亚洲精品| 午夜精品久久久久久久白皮肤| 99国产麻豆精品| 免费亚洲婷婷| 欧美成人69av| 国内精品亚洲| 性伦欧美刺激片在线观看| 亚洲一区二区三区视频播放| 欧美激情视频免费观看| 欧美成人午夜剧场免费观看| 国产在线拍揄自揄视频不卡99| 亚洲图片欧美午夜| 亚洲高清视频一区| 欧美一级久久久| 欧美日韩精品在线播放| 亚洲国产经典视频| 亚洲国产欧美久久| 久久亚洲一区二区| 免费久久精品视频| 一区二区亚洲| 老司机精品视频网站| 欧美gay视频| 亚洲电影免费在线观看| 久久久亚洲国产美女国产盗摄| 久热精品视频在线观看| 黄色亚洲网站| 久久久久久一区二区三区| 猛男gaygay欧美视频| 1769国产精品| 欧美成人综合网站| 亚洲老司机av| 亚洲综合二区| 国产欧美一区二区白浆黑人| 翔田千里一区二区| 欧美gay视频| 99精品视频免费在线观看| 欧美日韩精品一区二区天天拍小说 | 国产毛片精品国产一区二区三区| 一区二区三区国产精华| 亚洲欧美一区二区视频| 国产欧美日本| 久久人人97超碰国产公开结果 | 国产精品毛片一区二区三区 | 久久精品一二三| 尤物九九久久国产精品的分类| 玖玖在线精品| 一本色道久久88精品综合| 欧美在线观看视频在线| 在线国产精品一区| 欧美人在线视频| 性做久久久久久免费观看欧美| 久久视频这里只有精品| 亚洲精品三级| 国产精品久久久久久五月尺| 久久成人精品| 亚洲激情av| 欧美伊人久久久久久久久影院| 在线观看不卡av| 欧美午夜宅男影院| 久久夜色精品国产| 亚洲午夜免费福利视频| 免费中文日韩| 亚洲一区二区精品在线| 樱桃国产成人精品视频| 欧美午夜一区二区| 美脚丝袜一区二区三区在线观看 | 99国产一区二区三精品乱码| 久久国产免费看| 99国产精品99久久久久久| 国产日韩一区| 欧美日韩精选| 欧美不卡在线视频| 国产一区二区日韩精品| 欧美国产一区在线| 小处雏高清一区二区三区 | 91久久久久久久久| 欧美在线影院在线视频| 亚洲美女在线视频| 黄色亚洲大片免费在线观看| 欧美亚洲第一区| 欧美精品少妇一区二区三区| 久久久久久69| 亚洲欧美一区二区三区极速播放 | 亚洲美女精品成人在线视频| 麻豆av一区二区三区久久| 欧美在线91| 午夜精品久久久久久久蜜桃app |