我來自一個相當功能的編程背景,我不習慣(高效的)C++數據結構。我需要一個數據結構來保存多個元素,如struct element
中所述。在集合中,字段ID應該是唯一的。集合論數據結構
我想執行像在比較組{x1,x2,x3}
和{x4,x5}
我要確定交集{x5}
(或{x2}
其在這種情況下相等)和。減去集從其它時集合論即例如非常快的設定比較設置像例如{x1,x2,x3} \ {x5} = {x1,x3}
。
在C++的宇宙中是否存在「設置理論」數據結構?
struct element {
int id;
float value;
};
struct element x1 = {1, 1.0};
struct element x2 = {2, 2.0};
struct element x3 = {3, 3.0};
struct element x4 = {3, 3.1};
struct element x5 = {2, 2.0};
std :: set是你在找什麼。 http://www.cplusplus.com/reference/stl/set/請注意,您需要一個比較運算符。 – Lalaland
''中的'std :: set'。 http://stdcxx.apache.org/doc/stdlibug/8-2.html –
birryree
而且,在std :: set中有些東西在中,比如std :: set_union http://www.cplusplus.com/reference/算法/ –
Lalaland