Example #1
0
        public static void Main(String[] args)
        {
            Eqclass <int> x = Eqclass <int> .Make(3),
                          y = Eqclass <int> .Make(4),
                          z = Eqclass <int> .Make(5);

            x.Union(y);
            y.Union(z);
            Console.WriteLine(x.Find().Item);
            Console.WriteLine(y.Find().Item);
            Console.WriteLine(z.Find().Item);
        }
Example #2
0
        public void Union(Eqclass <T> that)
        {
            Eqclass <T> thatRep = that.Find(), thisRep = this.Find();

            if (thatRep != thisRep)
            {
                if (thatRep.rank == thisRep.rank)
                {
                    thisRep.link = thatRep;
                    thatRep.rank++;
                }
                else if (thatRep.rank > thisRep.rank)
                {
                    thisRep.link = thatRep;
                }
                else
                {
                    thatRep.link = thisRep;
                }
            }
        }