日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

STL_算法_区间的比較(equal、mismatch、 lexicographical_compare)

發布時間:2025/3/15 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 STL_算法_区间的比較(equal、mismatch、 lexicographical_compare) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

C++ Primer 學習中。。

?

簡單記錄下我的學習過程?(代碼為主)


//全部容器適用


equal(b,e,b2) ? ? ? //用來比較第一個容器[b,e)和第二個容器b2開頭,是否相等
equal(b,e,b2,p)


mismatch(b,e,b2) ? ?//用來查找兩個容器中第一個不相等的數據,返回迭代器
mismatch(b,e,b2,p)


lexicographical_compare(b,e,b2,e2) ? ? ?//用來比較第一個區間是否比第二個區間小
lexicographical_compare(b,e,b2,e2,p)

#include<iostream> #include<cstdio> #include<cstring> #include<vector> #include<list> #include<algorithm> using namespace std;/***************************************** //全部容器適用 equal(b,e,b2) //用來比較第一個容器[b,e)和第二個容器b2開頭。是否相等 equal(b,e,b2,p) mismatch(b,e,b2) //用來查找兩個容器中第一個不相等的數據,返回迭代器 mismatch(b,e,b2,p) lexicographical_compare(b,e,b2,e2) //用來比較第一個區間是否比第二個區間小 lexicographical_compare(b,e,b2,e2,p) *****************************************//************************************************************************************* std::equal 全部排序容器適用 algorithm -------------------------------------------------------------------------------------- template <class InputIterator1, class InputIterator2>bool equal ( InputIterator1 first1, InputIterator1 last1,InputIterator2 first2 );template <class InputIterator1, class InputIterator2, class BinaryPredicate>bool equal ( InputIterator1 first1, InputIterator1 last1,InputIterator2 first2, BinaryPredicate pred );//eg: template <class InputIterator1, class InputIterator2>bool equal ( InputIterator1 first1, InputIterator1 last1, InputIterator2 first2 ) {while ( first1!=last1 ){if (!(*first1 == *first2)) // or: if (!pred(*first1,*first2)), for pred versionreturn false;++first1; ++first2;}return true; } *************************************************************************************//************************************************************************************* std::mismatch 全部排序容器適用 algorithm -------------------------------------------------------------------------------------- template <class InputIterator1, class InputIterator2>pair<InputIterator1, InputIterator2>mismatch (InputIterator1 first1, InputIterator1 last1,InputIterator2 first2 );template <class InputIterator1, class InputIterator2, class BinaryPredicate>pair<InputIterator1, InputIterator2>mismatch (InputIterator1 first1, InputIterator1 last1,InputIterator2 first2, BinaryPredicate pred );//eg: template <class InputIterator1, class InputIterator2>pair<InputIterator1, InputIterator2>mismatch (InputIterator1 first1, InputIterator1 last1, InputIterator2 first2 ) {while ( (first1!=last1) && (*first1==*first2) ) // or: pred(*first1,*first2), for the pred version{ ++first1; ++first2; }return make_pair(first1,first2); } *************************************************************************************/ /************************************************************************************* std::lexicographical_compare 全部排序容器適用 algorithm -------------------------------------------------------------------------------------- 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 ); //eg: template <class InputIterator1, class InputIterator2>bool lexicographical_compare ( InputIterator1 first1, InputIterator1 last1,InputIterator2 first2, InputIterator2 last2 ) {while (first1!=last1){if (first2==last2 || *first2<*first1) return false;else if (*first1<*first2) return true;first1++; first2++;}return (first2!=last2); } *************************************************************************************/bool mypredicate (int i, int j) {return (i==j); }bool mycomp (char c1, char c2) {return tolower(c1)<tolower(c2); }int main() {//equal(b,e,b2) //用來比較第一個容器[b,e)和第二個容器b2開頭,是否相等//equal(b,e,b2,p)int myints[] = {20,40,60,80,100}; // myints: 20 40 60 80 100vector<int>myvector (myints,myints+5); // myvector: 20 40 60 80 100// using default comparison:if (equal (myvector.begin(), myvector.end(), myints))cout << "The contents of both sequences are equal." << endl;elsecout << "The contents of both sequences differ." << endl;myvector[3]=81; // myvector: 20 40 60 81 100// using predicate comparison:if (equal (myvector.begin(), myvector.end(), myints, mypredicate))cout << "The contents of both sequences are equal." << endl;elsecout << "The contents of both sequences differ." << endl;cout<<endl;/**-----------------------------------------------------------------------------Output:The contents of both sequences are equal.The contents of both sequences differ.-----------------------------------------------------------------------------**///mismatch(b,e,b2) //用來查找兩個容器中第一個不相等的數據,返回迭代器//mismatch(b,e,b2,p)list<int> mylist;for (int i=1; i<6; i++) mylist.push_back (i*10); // mylist: 10 20 30 40 50int myints2[] = {10,20,80,40,1024}; // myints2: 10 20 80 40 1024pair<list<int>::iterator,int*> mypair;// using default comparison:mypair = mismatch (mylist.begin(), mylist.end(), myints2);cout << "First mismatching elements: " << *mypair.first;cout << " and " << *mypair.second << endl;mypair.first++;mypair.second++;// using predicate comparison:mypair = mismatch (mypair.first, mylist.end(), mypair.second, mypredicate);cout << "Second mismatching elements: " << *mypair.first;cout << " and " << *mypair.second << endl;cout <<endl;/**-----------------------------------------------------------------------------Output:First mismatching elements: 30 and 80Second mismatching elements: 50 and 1024-----------------------------------------------------------------------------**///lexicographical_compare(b,e,b2,e2) //用來比較第一個區間是否比第二個區間小 (長度和ASCII碼)//lexicographical_compare(b,e,b2,e2,p)char first[]="apple"; // 5 letterschar second[]="apart"; // 5 letters eg:apartmentcout << "Using default comparison (operator<): ";if (lexicographical_compare(first,first+5,second,second+5))cout << first << " is less than " << second << endl;else if (lexicographical_compare(second,second+5,first,first+5))cout << first << " is greater than " << second << endl;elsecout << first << " and " << second << " are equivalent\n";cout << "Using mycomp as comparison object: ";if (lexicographical_compare(first,first+5,second,second+5,mycomp))cout << first << " is less than " << second << endl;else if (lexicographical_compare(second,second+5,first,first+5,mycomp))cout << first << " is greater than " << second << endl;elsecout << first << " and " << second << " are equivalent\n";/**-----------------------------------------------------------------------------Output:Using default comparison (operator<): apple is greater than apartUsing mycomp as comparison object: apple is greater than apart-----------------------------------------------------------------------------**/return 0; }

轉載于:https://www.cnblogs.com/cxchanpin/p/7289702.html

總結

以上是生活随笔為你收集整理的STL_算法_区间的比較(equal、mismatch、 lexicographical_compare)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 日韩不卡在线视频 | 亚洲精品爱爱 | 女人脱裤子让男人捅 | 处破女av一区二区 | 桥本有菜aⅴ一区二区三区 在线午夜电影 | 少妇熟女视频一区二区三区 | 成人aⅴ视频 | 日韩一区二区三区在线 | 日本视频免费在线播放 | 少妇视频在线观看 | 国产女人精品视频 | 国产午夜视频 | 欧美理论片在线观看 | 国产一区影院 | 黄色av网址大全 | 少妇做爰免费理伦电影 | 欧美做受喷浆在线观看 | 亚洲一卡二卡三卡四卡 | 成人无码av片在线观看 | 看片网址国产福利av中文字幕 | 欧美a网站 | 日韩在线中文字幕 | 国产日韩欧美二区 | 爆操女秘书 | 精品久久久久久久久久久久久 | 国产手机在线观看 | 午夜播放 | 国产精品88久久久久久妇女 | 爱露出 | 亚洲激情视频小说 | 午夜剧场黄色 | 婷婷四房综合激情五月 | 韩国电影一区 | 欧美日韩不卡一区二区三区 | 伊人伊人伊人 | 欧美三级韩国三级日本三斤 | 国产精品天天av精麻传媒 | 天天综合av | 国产精品自拍第一页 | 亚洲国产情侣 | 2018天天操| 久久久这里有精品 | 亚洲国产成人精品女人 | 亚洲精品乱码久久久久久蜜桃图片 | 五月天婷婷影院 | 美女又爽又黄免费视频 | 欧美群交射精内射颜射潮喷 | 国内精品人妻无码久久久影院蜜桃 | 黑人操欧美人 | 妺妺窝人体色WWW精品 | 色乱码一区二区三区 | 伊人久久大香线蕉综合网站 | av美女在线 | 一区二区三区视频免费在线观看 | 91精品国产91久久久久 | 国产精品一区免费观看 | 偷偷操不一样 | 葵司在线视频 | 7788色淫网站小说 | 欧美一级特黄aa大片 | 四虎网站最新网址 | 精品一区二区在线播放 | 第一章豪妇荡乳黄淑珍 | 亚洲第一网址 | 视色网 | 毛片.com | 性欧美18一19性猛交 | 一级黄色片免费在线观看 | 日本免费在线视频观看 | 欧美一区二区三区久久成人精品 | 欧美视频成人 | 国产精品亚洲一区二区 | 亚洲欧美国产一区二区三区 | 日韩高清在线一区二区 | 国产高清无遮挡 | 黑人巨大精品欧美一区二区免费 | 女人张开腿让男人桶爽 | 在线观看视频一区二区三区 | 亚洲国产理论 | 亚洲v欧美 | 一级肉体全黄裸片 | 性色一区二区三区 | 天天干天| 欧美精品日韩在线观看 | 蜜臀一区二区三区 | 天堂网亚洲 | 精品日本一区二区 | 色在线视频 | 一区二区精彩视频 | 国产成人三级在线观看视频 | 黄在线观看 | av不卡在线免费观看 | 蜜桃av在线| 欧美国产一区二区 | 爱情岛论坛亚洲线路一 | 日韩欧美一区二区一幕 | 国产精品久久久久久久久久久新郎 | 亚洲欧美婷婷 | 香蕉一级片 |