本文整理汇总了C++中DisjointSet::add方法的典型用法代码示例。如果您正苦于以下问题:C++ DisjointSet::add方法的具体用法?C++ DisjointSet::add怎么用?C++ DisjointSet::add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DisjointSet
的用法示例。
在下文中一共展示了DisjointSet::add方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
std::cerr << "Running Test for Disjoint Set..." << std::endl;
DisjointSet<int> test;
for (int i = 0; i < 10; ++i)
test.add(i);
for (int i = 0; i < 9; ++i) {
for (int j = i + 1; j < 10; ++j) {
ASSERT_CONDITION(test.isConnected(i, j) == false, "No connectivity check");
}
}
ASSERT_CONDITION(test.getNumElements() == 10, "Number of elements check");
ASSERT_CONDITION(test.getNumSets() == 10, "Number of sets check");
test.merge(1, 2);
test.merge(1, 5);
test.merge(2, 6);
test.merge(8, 5);
test.merge(3, 4);
test.merge(9, 7);
ASSERT_CONDITION(test.getNumElements() == 10, "Number of elements (after merge) check");
ASSERT_CONDITION(test.getNumSets() == 4, "Number of sets (after merge) check");
ASSERT_CONDITION(test.isConnected(1, 2) == true, "Connectivity (after merge) check");
ASSERT_CONDITION(test.isConnected(1, 5) == true, "Connectivity (after merge) check");
ASSERT_CONDITION(test.isConnected(1, 6) == true, "Connectivity (after merge) check");
ASSERT_CONDITION(test.isConnected(1, 8) == true, "Connectivity (after merge) check");
ASSERT_CONDITION(test.isConnected(3, 4) == true, "Connectivity (after merge) check");
ASSERT_CONDITION(test.isConnected(7, 9) == true, "Connectivity (after merge) check");
ASSERT_CONDITION(test.isConnected(0, 1) == false, "Connectivity (after merge) check");
ASSERT_CONDITION(test.isConnected(0, 3) == false, "Connectivity (after merge) check");
ASSERT_CONDITION(test.isConnected(0, 7) == false, "Connectivity (after merge) check");
return 0;
}