本文整理汇总了C++中DisjointSet::unionSets方法的典型用法代码示例。如果您正苦于以下问题:C++ DisjointSet::unionSets方法的具体用法?C++ DisjointSet::unionSets怎么用?C++ DisjointSet::unionSets使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DisjointSet
的用法示例。
在下文中一共展示了DisjointSet::unionSets方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(){
DisjointSet<int> s;
/*
* you fill in here to set up the disjoint set
*/
s.createSet(1);
s.createSet(2);
s.createSet(3);
s.createSet(4);
s.createSet(5);
s.createSet(6);
s.createSet(7);
s.createSet(8);
s.createSet(9);
s.unionSets(3,5);
s.unionSets(4,2);
s.unionSets(1,6);
s.unionSets(5,7);
s.unionSets(4,8);
s.unionSets(3,7);
s.unionSets(8,1);
assert(s.findSet(1) == s.findSet(6)); // 1 and 6 are connected.
assert(s.findSet(3) != s.findSet(6)); // 3 and 6 are not connected.
assert(s.findSet(1) == s.findSet(1)); // 1 and 1 are connected.
assert(s.findSet(3) == s.findSet(5)); // 3 and 5 are connected.
assert(s.findSet(3) != s.findSet(9)); // 3 and 9 are not connected.
cout<< "Done"<<endl;
}