#include #include #define N 10 int ID[N]; int size[N]; void init(){ int i; for(i=0; i ", p, q); // Use Quick-Find QF_union(p, q); // Use Quick-Find // QU_union(p, q); // Use Weighted Quick-Find // WQU_union(p, q); // Use Weighted Quick-Find with Path Compression // WQUPC_union(p, q); print_ID(); } void find_fc(int p, int q){ int connected; // Use Quick-Find connected = QF_find(p, q); // Use Quick-Union // connected = QU_find(p, q); // Use Weighted Quick-Find // connected = WQU_find(p, q); // Use Weighted Quick-Find with Path Compression // connected = WQUPC_find(p, q); if(connected) printf("Find(%d, %d), YES.\n", p, q); else printf("Find(%d, %d), NO.\n", p, q); } int main() { int p, q; /* You need goto union_fc() function and find_fc() function to select which method you want to use (the default method is Quick-Find). And then you can run the code. */ init(); printf("Initialize -> "); print_ID(); p = 4; q = 3; union_fc(p, q); p = 3; q = 8; union_fc(p, q); p = 6; q = 5; union_fc(p, q); p = 9; q = 4; union_fc(p, q); p = 2; q = 1; union_fc(p, q); p = 8; q = 9; find_fc(p, q); p = 5; q = 0; find_fc(p, q); p = 5; q = 0; union_fc(p, q); p = 7; q = 2; union_fc(p, q); p = 6; q = 1; union_fc(p, q); p = 5; q = 0; find_fc(p, q); p = 7; q = 3; union_fc(p, q); }