Пример #1
0
        public static void Main(String[] args)
        {
            int N  = StdIn.ReadInt();
            UF  uf = new UF(N);

            // read in a sequence of pairs of integers (each in the range 0 to N-1),
            // calling find() for each pair: If the members of the pair are not already
            // call union() and print the pair.
            while (!StdIn.IsEmpty())
            {
                int p = StdIn.ReadInt();
                int q = StdIn.ReadInt();

                if (uf.Connected(p, q))
                {
                    continue;
                }
                uf.union(p, q);

                Console.WriteLine(p + " " + q);
            }

            Console.WriteLine(uf.Count + " components");
        }
Пример #2
0
        public static void Main(String[] args)
        {
            int N = StdIn.ReadInt();
            UF uf = new UF(N);

            // read in a sequence of pairs of integers (each in the range 0 to N-1),
            // calling find() for each pair: If the members of the pair are not already
            // call union() and print the pair.
            while (!StdIn.IsEmpty())
            {
                int p = StdIn.ReadInt();
                int q = StdIn.ReadInt();
                
                if (uf.Connected(p, q)) continue;
                uf.union(p, q);

                Console.WriteLine(p + " " + q);
            }

            Console.WriteLine(uf.Count + " components");
        }
Пример #3
0
 public void QuickUnionUnionFindMedium()
 {
     IUnionFind unionFind = new UF();
      CommonUFFunctionalTests.UnionFindCommon("Algs4-Data\\MediumUF.txt", unionFind);
      Assert.AreEqual(3, unionFind.Count);
 }
Пример #4
0
 public void UnionFindTiny()
 {
     IUnionFind unionFind = new UF();
      CommonUFUnitTests.CommonUnionFindTiny(unionFind);
 }
Пример #5
0
 public void QuickUnionUnionFindLarge()
 {
     IUnionFind unionFind = new UF();
      CommonUFFunctionalTests.UnionFindCommon("Algs4-Data\\LargeUF.txt", unionFind);
      Assert.AreEqual(6, unionFind.Count);
 }