예제 #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("data file name:");
            string file = Console.ReadLine();

            string[] RawSet = File.ReadAllLines(file);
            int      N      = Convert.ToInt32(RawSet[0]);

            string[] ProbSet = new string[RawSet.Length - 1];
            for (int i = 1; i < RawSet.Length; i++)
            {
                ProbSet[i - 1] = RawSet[i];
            }

            QuickUnion uf = new QuickUnion(N);

            foreach (string word in ProbSet)
            {
                string[] Pair = word.Split(" ");
                int      p    = Convert.ToInt32(Pair[0]);
                int      q    = Convert.ToInt32(Pair[1]);
                if (uf.IsConnected(p, q))
                {
                    continue;
                }
                uf.Union(p, q);
                Console.WriteLine(p + " " + q + " are now connected");
            }

            Console.WriteLine(uf.Count() + " total components");
        }
예제 #2
0
        public void UnionTests()
        {
            var union = new QuickUnion(10);

            union.Union(5, 8);

            Assert.IsTrue(union.Connected(5, 8));
            Assert.IsFalse(union.Connected(5, 9));
        }
        static void Main(string[] args)
        {
            string[]   file     = File.ReadAllLines(@"\\GMRDC1\Folder Redirection\nikita.ulianov\Desktop\friends.txt");
            QuickUnion blobfish = new QuickUnion(int.Parse(file[0]));

            for (int i = 1; i < file.Length; i++)
            {
                string[] temp = file[i].Split(' ');
                blobfish.Union(int.Parse(temp[0]), int.Parse(temp[1]));
            }
            var dog = blobfish.GetAllGroups();

            ;
        }