Talk:Disjoint set data structure (C)

From LiteratePrograms
Jump to: navigation, search

In the "Find" function, there are two lines where one thing is assigned to the other, and then is assigned back.

temp = node->parent;
node->parent = temp;

This seems silly. Can someone check it? Also, it seems like the "temp" variable is not really necessary. Also, the "temp" variable is declared in the middle of the function, which is not allowed in C before C99. Is this intended? --Spoon! 22:20, 28 January 2008 (PST)

From the article: The idea is that all nodes we visit when traversing up from a node to the root are in the same tree, and so they might as well be pointing directly at the root. It seems like the code should look like this (substituting temp with root):
temp = node->parent;
node->parent = root;
node = temp;
So we still need the temp variable. I am, however, not sure about this, so hopefully someone else will check this and correct the article. The temp variable should be declared at the top of scope. I have fixed that. Ahy1 01:16, 29 January 2008 (PST)
hijacker
hijacker
hijacker
hijacker