Well I spoke to my professor today and he couldn't understand it either, this is clearly some sort of CS black magic that is impenetrable for physicists!
I worked through the example stahta01 kindly provided though, and tried coding it (i'll include it below).
I think I understand a bit better now... setting y=labels[y] does not necessarily mean that labels[y]=y ??! I see what you meant about a mathematical mindset, consider my mind expanded lol.
Thanks a lot for your help, no doubt ill be back with more questions soon!
Code:
#include <stdio.h>
int labels[6] = {0,0,2,2,3,3};
int find(int x);
int main()
{
int x=5, y=0;
y = find(x);
printf("find(x) returns %d.\n", y);
return 0;
}
int find(int x) {
int y = x;
while (labels[y] != y){
printf("loop called! y = %d\n", y);
y = labels[y];
}
while (labels[x] != x) {
int z = labels[x];
labels[x] = y;
x = z;
}
return y;
}
/* ******************** output **********************
loop called! y = 5
loop called! y = 3
find(x) returns 2.
Process returned 0 (0x0) execution time : 0.087 s
Press any key to continue.
************************************************** */