STL集合運算1

2021-09-30 06:34:23 字數 895 閱讀 1505

<< the annotated stl sources (using sgi stl >>

6.5 set

6.5.1 set_union

集合的並運算(s1 u s2)。注意s1和s2內的元素不一定為惟一的,若x在s1出現n次,在x2出現m次,則最終輸出max(n,m)個x.該演算法是穩定的。

template

outputiterator

set_union(inputiterator1 first1, inputiterator1 last1,

inputiterator1 first2, inputiterator2 last2,

outputiterator result)

else if(*first1 > * first2)

else

++result; }

return copy(first2, last2,copy(first1, last1, result)); }

6.5.2 set_intersection

求集合的交集.若x在s1**現n次,在s2**現m次,則最終輸出min(n,m)次。

該演算法也是穩定的。

template

class outputiterator>

outputiterator

set_intersection(

inputiterator1  first1, inputiterator1,last1,           inputiterator2  first2, inputiterator2 last2,

outputiterator result) // end of else

}//end of while

}// end of function

STL 集合運算

description 集合的運算就是用給定的集合去指定新的集合。設a和b是集合,則它們的並差交補集分別定義如下 a b a b a b sa sb input 第一行輸入乙個正整數t,表示總共有t組測試資料。t 200 然後下面有2t行,每一行都有n 1個數字,其中第乙個數字是n 0 n 100 ...

STL中集合的並 交 差 運算

並集運算 總結主要是記錄下來供自己日後參考,因為一段時間不用就忘了,所以是按照自己容易理解的方式寫的,不過任然希望各位可以指出錯誤和欠缺的地方,共同進步。1 template outputiterator set union inputiterator1 first1,inputiterator1 ...

集合 集合運算

update pop remove 集合的運算 集合和字典相同都用 但是集合沒有鍵,只有元素值 集合中存貯列表會報錯,因為只能存貯不可變序列,而列表是可變的 直接建立 se print se,type se class set 通過set 建立 se set 1 2,3 4 這裡函式中用列表,因為要...