public static bool UnifySetsForEachOf( Node nodeA, Node nodeB ) { Node nodeARep = nodeA.FindRepresentative(); Node nodeBRep = nodeB.FindRepresentative(); if( nodeARep == nodeBRep ) return false; // Arbitrarily making nodeA subordinate, if you will, to nodeB. nodeARep.nodeLink = nodeBRep; return true; }
public static bool AreMembersOfSameSet( Node nodeA, Node nodeB ) { Node nodeARep = nodeA.FindRepresentative(); Node nodeBRep = nodeB.FindRepresentative(); if( nodeARep == nodeBRep ) return true; return false; }