小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

幾個(gè)STL算法:includes,set

 ONLY_影 2015-02-06

includes:

測試有序序列中是否包含另一個(gè)序列的全部元素。

template<class inputIterator1, class inputIterator2>

bool includes(inputIterator1 first1, inputIterator1 last1,

                     inputIterator2 first2, inputIterator2 last2);

template<class inputIterator1 , class inputIterator2, class Comp>

bool includes(inputIterator1 first1, inputIterator1 last1,

                     inputIterator2 first2, inputIterator2 last2,

                     Comp cmp);

兩個(gè)序列必須都是排序的且相同的排序,Comp必須和兩個(gè)序列用相同的排序函數(shù)對象。

 

鑒于以上特點(diǎn),用std::set<T>作為容器比較好。

 

 

set_differrence:包含在第一個(gè)有序集合中,但不包含第二個(gè)有序集合中的元素,這些不同的元素復(fù)制到最后一個(gè)參數(shù)中,最后一個(gè)參數(shù)是一個(gè)保存這些元素的容器的首迭代器,這個(gè)容器必須預(yù)先分配足夠的空間來容納元素。這些不同的元素也是有序的且排序方式與源有序集合一樣,另外Comp也必須和源有序集合采用同樣的排序方式。

兩個(gè)有序序列不可以有重疊。

返回的是在有序序列1而不是有序序列2中的元素。

 

template<class inputIterator1, class inputIterator2,

                class outputIterator>

outputIterator result =

set_difference(inputIterator1 first1, inputIterator1 last1,

                      inputIterator2 first2, inputIterator2 last2,

                      outputIterator first);

 

template<class inputIterator1, class inputIterator2,

                class outputIterator>

outputIterator result =

set_difference(inputIterator1 first1, inputIterator1 last1,

                      inputIterator2 first2, inputIterator2 last2,

                      outputIterator first, Comp cmp);

還是用set容器比較好。

 

 

set_intersection:同時(shí)包含第一個(gè)和第二個(gè)集合中的元素,這些元素被復(fù)制到最后一個(gè)參數(shù)中,最后一個(gè)參數(shù)是一個(gè)保存這些元素的容器的首迭代器,這個(gè)容器必須預(yù)先分配足夠的空間來容納元素。兩個(gè)集合都必須是有序的且是相同的排序。

基本上和set_difference用法一樣,只是找出交集而已。還是用set。

 

 

set_symmetric_difference:包含在第一個(gè)集合但是不包含在第二個(gè)集合中的元素,包含在第2個(gè)集合但是不包含在第1個(gè)集合中的元素,同時(shí)被復(fù)制到最后一個(gè)參數(shù)中。用法跟基本上和set_difference用法一樣。兩個(gè)集合都必須是有序的且是相同的排序。

 

 

set_union:包含兩個(gè)集合中所有元素的幾個(gè),同時(shí)被復(fù)制到最后一個(gè)集合中。 兩個(gè)集合都必須是有序的且是相同的排序。

也就是求兩個(gè)元素的公共元素,用法基本同set_difference。

 

 

pre_permutation:重排區(qū)間中的元素,使得源序列變成按照字典序列的上一個(gè)序列,其中的“上一個(gè)”可由用戶自己定義。

template<class Iterator>

bool pre_permutation(Iterator first, Iterator last);

 

 

template<class Iterator, class Comp>

bool pre_permutation(Iterator first, Iterator last, Comp cmp);

int main()
{
 vector<int> p;
 p.push_back(2);
 p.push_back(2);
 p.push_back(1);
 p.push_back(-1);
 p.push_back(0);

 do {
  copy(p.begin(), p.end(), ostream_iterator<int>(cout, " "));
  cout << "/n";
 } while (prev_permutation(p.begin(), p.end()));
}

 

next_permutation的用法同pre_permutation.

 

 

    本站是提供個(gè)人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多