Пример #1
0
        bool Merge(KruskalNode other)
        {
            KruskalNode rootThis  = this.Root();
            KruskalNode rootOther = other.Root();

            if (rootThis == rootOther)
            {
                return(false);
            }
            if (rootThis.height < rootOther.height)
            {
                rootThis.parent = rootOther;
            }
            else
            {
                rootOther.parent = rootThis;
                if (rootThis.height == rootOther.height)
                {
                    rootThis.height += 1;
                }
            }
            return(true);  // merge successful
        }
Пример #2
0
 bool InSameSet(KruskalNode other)
 {
     return(this.Root() == other.Root());
 }