B. To test this class, implement a test driver something like this:
#include <conio.h>
#include <iostream.h>
int main()
{
unsigned int x[] = {1, 3, 3, 1, 3, 8, 1,3,3,3,3,14,16,14,1,1};
// This is Exer.
unsigned int y[] = {2, 4, 5, 7, 6, 9, 8, 10, 11, 12, 13,15,0,
16,3, 14};//8.1
data
int NSIZE = 16;
DisjointSet djs(17);
for (i= 0; i< NSIZE; i++)
djs.Union(x[i], y[i]);
for (i= 0; i<=16; i++){
for(j= i+1; j <=16; j++)
if(djs.Find(i,
j))
cout
<< "{" << i << "," << j << "} equivalent"
<< endl;
else
cout
<< "{" << i << "," << j << "} Not equivalent"
<< endl;
cout <<"Press any key to
continue"<< endl;
while (!kbhit()); // not ver C++
like, but will pause the screen
getch ();//till
you touch a key
}
for (int k = 0; k<=16 ;k++)
cout
<< djs.Find (k) << ' ';
cout << endl;
return 0;
}
C. After being sure it works, use it to time N unions of random integer pairs from a file integerPairs.zip that I will put in our download area. Do it for Union, Union by size, and UnionByHeight.
Notes:
1. Conventions: The universe of set elements is 0,1...Size-1. Consequently, s[0] is used, and the sentinel used to mark roots must not be 0; use a negative integer instead. For calculation of average node depth, assume root nodes have a depth of 0.
3 The author’s single-argument Find(x) function is the same as ours in that it returns an integer which is the root of the tree containing x. However, he implements it recursively. I want you to do a non-recursive implementation. It is very easy to do and is more efficient.