コード例 #1
0
        /// <summary>
        /// Uses the given union find object to run the commands.
        /// </summary>
        /// <param name="algo"></param>
        /// <param name="commands"></param>
        public static void Run(IUnionFind algo, int[,] commands)
        {
            int x, y;

            for (int i = 0; i < commands.GetLength(0); i++)
            {
                x = commands[i, 0];
                y = commands[i, 1];
                if (algo.CheckIfConnected(x, y) == false)
                {
                    Console.WriteLine("CHECK:\t{0} and {1} are not connected.", x, y);
                    algo.CreateUnion(x, y);
                    Console.WriteLine("UNION:\t{0} and {1} where successfully connected.", x, y);
                }
                else
                {
                    Console.WriteLine("CHECK:\t{0} and {1} are already connected.", x, y);
                }
            }
        }