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


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

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


在下文中一共展示了DisjointSet::findSet方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: unionEquals

void unionEquals(vl & G, DisjointSet &ds, CmpByMask cmp)
{
	for (uint i = 0; i < G.size() - 1; ++i)
	{
		/* if previous less than next */
		if (cmp(G[i], G[i + 1]))
		{
			continue;
		}

		/* two adjacent nodes are equal */
		/* check if they belong to different component and union them */
		/* BUG: keep index in G */
		if (ds.findSet(i) != ds.findSet(i + 1))
		{
			ds.unionNodes(i, i + 1);
		}
	}
}
开发者ID:ykirpichev,项目名称:experiments,代码行数:19,代码来源:main.cpp

示例2: 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;
}
开发者ID:snayski,项目名称:School-Work,代码行数:32,代码来源:DStest0.cpp

示例3: main

int main() {
	DisjointSet djset;
	DisjointSet::NodePtr id[3];
	id[0] = djset.makeSet(0);
	id[1] = djset.makeSet(1);
	id[2] = djset.makeSet(2);

	djset.linkSets(id[0], id[1]);
	djset.linkSets(id[1], id[2]);

	DisjointSet::SetIdentifier t1 = djset.findSet(id[0]);
	DisjointSet::SetIdentifier t2 = djset.findSet(id[2]);
}
开发者ID:OasisGallagher,项目名称:CLRS,代码行数:13,代码来源:21.2-5.cpp


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