本文整理汇总了C++中DisjointSet::MakeSet方法的典型用法代码示例。如果您正苦于以下问题:C++ DisjointSet::MakeSet方法的具体用法?C++ DisjointSet::MakeSet怎么用?C++ DisjointSet::MakeSet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DisjointSet
的用法示例。
在下文中一共展示了DisjointSet::MakeSet方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MSTAlgo
double Graph::MSTAlgo() {
DisjointSet<Vertex>* A = new DisjointSet<Vertex>(n);
double totalweight = 0;
for(int i = 0; i < n; ++i){
A->MakeSet(i, AdjacencyList[i]->getElem());
}
sortEdge();
for(int i = 0; i < EdgeList.size(); ++i){
if(A->FindSet(EdgeList[i]->vertex_i)->getKey() != A->FindSet(EdgeList[i]->vertex_j)->getKey()){
A->Union(*(A->FindSet(EdgeList[i]->vertex_i)), *(A->FindSet(EdgeList[i]->vertex_j)));
totalweight += EdgeList[i]->weight;
MST.push_back(EdgeList[i]);
}
}
return totalweight;
}
示例2: main
int main(int argc, char *argv[]) {
DisjointSet ds;
for (int set_number=0; set_number<DSET_SIZE; ++set_number) {
ds.MakeSet(set_number);
}
srand(time(NULL));
int unions = 0;
int attempts = 0;
while (ds.size() > 1) {
// generate random couples and do Union operations, up to when there is
// only a single set left.
int x = rand() % DSET_SIZE;
int y = rand() % DSET_SIZE;
if (ds.Union(x,y)) {
unions += 1;
} else {
attempts += 1;
}
//std::cout << ds.toDot() << std::endl;
}
std::cerr << "unions=" << unions << ", attempts=" << attempts << std::endl;
std::cout << ds.toDot() << std::endl;
return 0;
}