I'm Studying the Quick-Union algorithm but can't exactly understand this code:
#include <stdio.h>
#define N 10000
main()
{
int i,p,t,id[N];
for (i = 0; i < N ; i++) id[i]= i;
while (scanf ("%d %d\n" , &p, &q) == 2)
{
for(i = p; i != id[i]; i = id[i]) ;
for (j = q; j != id[j]; j = id[j]) ;
if (i == j) continue;
id [i] = j ;
}
}
my main problem is the for
loop. if the condition
and the init
are met, what does the increment statement do?
NOTICE: This is out of a textbook not my code!