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

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 閱讀(896) 評論(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>
            国产精品人成在线观看免费| 亚洲欧美日韩综合| 一区二区国产日产| 精品成人一区二区三区四区| 日韩一区二区免费看| 韩国在线视频一区| 午夜精品久久久久久久| 一本色道久久综合亚洲精品婷婷 | 亚洲日本中文字幕区| 欧美一区成人| 羞羞视频在线观看欧美| 欧美网站在线| 亚洲精品一区二区三区蜜桃久 | 亚洲区中文字幕| 狠狠色综合日日| 欧美中文日韩| 欧美在线黄色| 国产一区视频在线看| 性高湖久久久久久久久| 午夜精品国产| 国产色婷婷国产综合在线理论片a| 亚洲免费黄色| 国产精品99久久久久久久vr| 免费看av成人| 亚洲高清在线| 9国产精品视频| 欧美日本国产一区| 日韩视频专区| 性欧美video另类hd性玩具| 国产精品久久99| 亚洲专区欧美专区| 久久aⅴ国产欧美74aaa| 国产亚洲欧美一区二区| 久久国产婷婷国产香蕉| 久久中文字幕导航| 亚洲二区三区四区| 欧美高清在线视频观看不卡| 日韩视频在线永久播放| 亚洲欧美中文日韩v在线观看| 国产精品久久久久秋霞鲁丝 | 麻豆久久精品| 亚洲人精品午夜| 亚洲与欧洲av电影| 国产网站欧美日韩免费精品在线观看| 欧美亚洲免费电影| 免费不卡视频| 亚洲少妇最新在线视频| 国产美女精品| 欧美96在线丨欧| 亚洲先锋成人| 久久综合久久综合这里只有精品 | 国产日韩精品视频一区二区三区| 欧美一区二区三区视频| 欧美高清在线| 在线中文字幕一区| 国产亚洲成av人片在线观看桃| 久久狠狠亚洲综合| 日韩一级精品视频在线观看| 久久精品亚洲一区二区三区浴池| 1024国产精品| 国产精品久久久久久一区二区三区| 欧美一区二区三区四区高清 | 这里只有精品在线播放| 久久免费高清| 亚洲免费在线视频一区 二区| 好吊色欧美一区二区三区四区| 欧美精品三区| 欧美在线观看网址综合| 亚洲精品久久久久久久久| 欧美伊人久久久久久久久影院| 在线免费观看成人网| 欧美视频一区二区在线观看 | 99国产麻豆精品| 国产一区二区三区在线观看精品| 欧美黄污视频| 久久久久久久综合狠狠综合| 亚洲桃色在线一区| 欧美高清在线| 开心色5月久久精品| 亚洲在线视频| 日韩亚洲在线观看| 黄色影院成人| 国产伦精品一区二区三区免费迷| 欧美福利在线| 久久中文字幕一区| 欧美一区影院| 亚洲专区一二三| 中文av字幕一区| 亚洲区中文字幕| 亚洲国产经典视频| 嫩草影视亚洲| 久久亚洲美女| 久久精品国产96久久久香蕉| 亚洲影院色无极综合| 99精品视频一区二区三区| 亚洲第一天堂av| 韩国一区电影| 国产在线乱码一区二区三区| 国产精品一国产精品k频道56| 欧美视频一区二区| 欧美日韩三区| 欧美视频官网| 欧美日韩一区二区精品| 欧美三级视频| 欧美色大人视频| 国产精品v欧美精品v日韩| 国产精品av免费在线观看| 欧美日韩中文字幕在线| 国产精品国色综合久久| 欧美日韩中文字幕在线视频| 欧美婷婷在线| 国产精品专区一| 国产日韩一区二区三区在线| 国产一级一区二区| 在线播放日韩| 91久久精品一区| 亚洲精品在线电影| 一本色道久久88精品综合| av成人黄色| 亚洲欧美日韩精品一区二区 | 久久久久久久999精品视频| 欧美在线视频免费| 久久久久国产精品人| 麻豆成人综合网| 欧美日韩1区2区3区| 欧美视频中文字幕| 国产人成精品一区二区三| 经典三级久久| 亚洲精品视频二区| 亚洲欧美视频在线观看| 久久精品盗摄| 欧美77777| 亚洲免费高清| 久久精品国产视频| 欧美大胆a视频| 国产精品一区二区三区久久| 在线观看欧美日本| 一本一本久久a久久精品综合麻豆| 亚洲丝袜av一区| 久久久久综合| 亚洲精品国产品国语在线app | 欧美午夜无遮挡| 韩日视频一区| 在线一区二区三区四区| 久久久久久夜| 亚洲日韩视频| 欧美一区三区三区高中清蜜桃| 免费观看成人www动漫视频| 欧美日韩中文字幕日韩欧美| 国内视频一区| 亚洲图片自拍偷拍| 久久亚洲电影| 亚洲天堂成人在线视频| 久久久久欧美精品| 国产精品欧美日韩| 亚洲人线精品午夜| 久久久久综合网| 亚洲图片在线| 欧美激情视频网站| 国内精品久久久久影院薰衣草| 亚洲作爱视频| 欧美激情第9页| 欧美伊人久久| 国产伦一区二区三区色一情| 日韩午夜在线观看视频| 久久亚洲二区| 午夜精品久久久久久久久| 欧美日韩国产天堂| 亚洲国产精品视频| 久久综合给合久久狠狠色| 亚洲一区二区三区精品在线| 欧美jjzz| 亚洲国产成人在线播放| 久久久精品久久久久| 一区二区三区导航| 欧美高清视频一二三区| 亚洲成色777777在线观看影院| 久久爱91午夜羞羞| 亚洲一区二区高清视频| 欧美日韩精品免费| 亚洲麻豆一区| 亚洲国产裸拍裸体视频在线观看乱了中文 | 欧美gay视频| 亚洲经典一区| 欧美激情一区二区| 久久久999成人| 国内精品久久久久影院优| 久久久99精品免费观看不卡| 亚洲愉拍自拍另类高清精品| 国产精品免费小视频| 午夜精品免费在线| 亚洲婷婷综合色高清在线| 国产精品高潮呻吟| 亚洲一区二区三区在线播放| 日韩视频免费观看高清在线视频| 欧美成黄导航| 日韩午夜中文字幕| 一本色道久久综合亚洲精品高清| 欧美激情女人20p| 正在播放欧美一区|