当前位置: 首页>>代码示例>>C++>>正文


C++ DisjointSet::isConnected方法代码示例

本文整理汇总了C++中DisjointSet::isConnected方法的典型用法代码示例。如果您正苦于以下问题:C++ DisjointSet::isConnected方法的具体用法?C++ DisjointSet::isConnected怎么用?C++ DisjointSet::isConnected使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DisjointSet的用法示例。


在下文中一共展示了DisjointSet::isConnected方法的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;
}
开发者ID:Harsha03,项目名称:coursera-courses,代码行数:39,代码来源:Test_DisjointSet.cpp


注:本文中的DisjointSet::isConnected方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。