public void Test_Find()
        {
            QuickFinder uf = new QuickFinder(3);

            uf.Union(0, 1);
            uf.Union(0, 2);

            Assert.Equal(2, uf.Find(1));
        }
        public void Test_IsConnected()
        {
            QuickFinder uf = new QuickFinder(3);

            uf.Union(0, 1);
            uf.Union(0, 2);

            Assert.True(uf.IsConnected(0, 1));
        }
        public void Test_Count()
        {
            QuickFinder uf = new QuickFinder(5);

            //Component 1
            uf.Union(0, 1);
            uf.Union(0, 2);

            //COmponent 2
            uf.Union(3, 4);

            Assert.Equal(2, uf.Count);
        }
Пример #4
0
        static void Main(string[] args)
        {
            var quickFinder = new QuickFinder(10);

            quickFinder.Union(1, 3);
            /*0 3 2 3 4 5 6 7 8 9 */
            quickFinder.Union(3, 8);
            /*0 8 2 8 4 5 6 7 8 9 */
            quickFinder.Union(7, 4);
            /*0 8 2 8 4 5 6 4 8 9 */
            quickFinder.Union(5, 8);
            /*0 8 2 8 4 8 6 4 8 9 */

            Console.WriteLine(quickFinder.Find(1, 5));

            quickFinder.Print();
        }
        public void Test_NotConnected()
        {
            QuickFinder uf = new QuickFinder(3);

            uf.Union(0, 1);

            Assert.False(uf.IsConnected(0, 2));
        }