-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestFastDisjSets.cpp
More file actions
32 lines (27 loc) · 899 Bytes
/
TestFastDisjSets.cpp
File metadata and controls
32 lines (27 loc) · 899 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream.h>
#include "DisjSets.h"
// Test main; all finds on same output line should be identical
int main( )
{
int numElements = 128;
int numInSameSet = 16;
DisjSets ds( numElements );
int set1, set2;
for( int k = 1; k < numInSameSet; k *= 2 )
{
for( int j = 0; j + k < numElements; j += 2 * k )
{
set1 = ds.find( j );
set2 = ds.find( j + k );
ds.unionSets( set1, set2 );
}
}
for( int i = 0; i < numElements; i++ )
{
cout << ds.find( i ) << "*";
if( i % numInSameSet == numInSameSet - 1 )
cout << endl;
}
cout << endl;
return 0;
}