Example #1
0
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;
}