C++ STL集合數據結構是否具有集合差異運算符?C++ STL集合差異
58
A
回答
11
是的,算法標題中有一個set_difference函數。
編輯:
FYI,所述一組數據結構能夠有效地使用該算法,如在其documentation說明。該算法不僅適用於集合,而且適用於排序集合上的任何迭代器對。
正如其他人所說,這是一種外部算法,而不是一種方法。推測這對你的應用程序來說很好。
1
不是作爲一種方法,但有外部算法功能set_difference
template <class InputIterator1, class InputIterator2, class OutputIterator>
OutputIterator set_difference(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2,
OutputIterator result);
1
顯然,它的作用。
4
不是「經營者」的語感,但在標準庫的set_difference算法:
http://www.cplusplus.com/reference/algorithm/set_difference.html
當然,其他的基本設置操作都存在過 - (聯合等),正如鏈接文章末尾的「另見」部分所建議的。
119
是的,它在<algorithm>
,被稱爲:std::set_difference
。用法:
#include <algorithm>
#include <set>
#include <iterator>
// ...
std::set<int> s1, s2;
// Fill in s1 and s2 with values
std::set<int> result;
std::set_difference(s1.begin(), s1.end(), s2.begin(), s2.end(),
std::inserter(result, result.end()));
最後,設定result
將包含s1-s2
。
2
所選答案是正確的,但有一些語法錯誤。
而不是
#include <algorithms>
使用
#include <algorithm>
而不是
std::insert_iterator(result, result.end()));
使用
std::insert_iterator<set<int> >(result, result.end()));
0
我們可以只使用
set_difference(set1.begin(), set1.end(), set2.begin(). set2,end(),std::back_inserter(result)).
1
再次,提高救援:
#include <string>
#include <set>
#include <boost/range/algorithm/set_algorithm.hpp>
std::set<std::string> set0, set1, setDifference;
boost::set_difference(set0, set1, std::inserter(setDifference, setDifference.begin());
setDifference將包含SET0,SET1。
0
C++沒有定義一組差分算子,但你可以定義自己的(使用其它響應給定的代碼):
template<class T>
set<T> operator -(set<T> reference, set<T> items_to_remove)
{
set<T> result;
std::set_difference(
reference.begin(), reference.end(),
items_to_remove.begin(), items_to_remove.end(),
std::inserter(result, result.end()));
return result;
}
相關問題
- 1. C++ STL集合使用
- 2. C++ STL集合和C#集合的比較?
- 3. C++ STL集:我可以使用upper_bound()來查找數字與集合元素的最小差異嗎?
- 4. C++ STL集合:與外在狀態
- 5. C++ stl集合或鏈接列表
- 6. C++:STL:集合:存儲值常量性
- 7. STL集合與單個鍵
- 8. PHP中對象的差異集合
- 9. C++中max_element和minmax_element的行爲差異STL
- 10. C++/STL:兩組異或
- 11. 差異數據集
- 12. 差異合成屬性的目標C
- 13. 差之間PowerShell和C#枚舉集合
- 14. 差異在C++
- 15. 如何:在Java中找到兩個集合之間的集合差異
- 16. 聯合,交集和設置差異的Java收集方法
- 17. 如何獲得R中兩個集合的差異?
- 18. STL集合= =運算符的問題
- 19. Linq統計集合中列表中的差異數
- 20. 袋子差異(類似於setdiff()但不適用於集合)
- 21. 發現在不同的列值的集合中值的差異
- 22. 結果差異C#
- 23. 差異 - 在Objective-C
- 24. C++構造差異
- 25. C#篩選差異
- 26. 分組集的差異
- 27. 什麼是stl集合的C#等價物?
- 28. 爲什麼命名C++ STL集合的容器的count()方法?
- 29. 差異,C++,C#和Java
- 30. 在STL集合的比較對象中使用可設置的公差
這是對_any_對有序容器的使用。 – xtofl 2008-11-12 14:16:15
好點...我在編輯中添加了一個註釋。 – 2008-11-12 14:43:32