示例#1
0
        static void Main(string[] args)
        {
            QuickUnionUF qf = new QuickUnionUF(20);

            qf.Union(1, 2);
            qf.Union(3, 2);
            Console.WriteLine(qf.Conected(2, 3).ToString());
            Console.WriteLine(qf.Conected(1, 2).ToString());
            Console.WriteLine(qf.Conected(1, 10).ToString());
        }
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            Console.WriteLine("Enter Length:");
            int          i      = Convert.ToInt32(Console.ReadLine());
            QuickUnionUF quf    = new QuickUnionUF(i);
            int          choice = 1;

            while (choice != 3)
            {
                Console.WriteLine("Select operation");
                Console.WriteLine("1. Add Connection");
                Console.WriteLine("2. Check Connection");
                Console.WriteLine("3. Exit");
                Console.WriteLine("Enter your choice");
                choice = Convert.ToInt16(Console.ReadLine());
                int p = 0;
                int q = 0;
                if (choice != 3)
                {
                    Console.WriteLine("Add / Check connection between two points - select between 0 and " + (i - 1).ToString());
                    Console.WriteLine("Enter point p ");
                    p = Convert.ToInt16(Console.ReadLine());
                    Console.WriteLine("Enter point q ");
                    q = Convert.ToInt16(Console.ReadLine());
                }
                switch (choice)
                {
                case 1:
                    quf.union(p, q);
                    break;

                case 2:
                    bool b = quf.connected(p, q);
                    Console.WriteLine("Are both points connected ?");
                    Console.WriteLine(b.ToString());
                    break;

                default:
                    break;
                }
            }
            Console.ReadLine();
        }
		public static void Main (string[] args)
		{
			Console.WriteLine ("Hello World!");
			Console.WriteLine ("Enter Length:");
			int i = Convert.ToInt32(Console.ReadLine());
			QuickUnionUF quf = new QuickUnionUF (i);
			int choice = 1;
			while (choice != 3) {
				Console.WriteLine ("Select operation");
				Console.WriteLine ("1. Add Connection");
				Console.WriteLine ("2. Check Connection");
				Console.WriteLine ("3. Exit");
				Console.WriteLine ("Enter your choice");
				choice = Convert.ToInt16 (Console.ReadLine ());
				int p = 0 ;
				int q = 0 ;
				if (choice != 3) {
					Console.WriteLine ("Add / Check connection between two points - select between 0 and " + (i - 1).ToString ());
					Console.WriteLine ("Enter point p ");
					p = Convert.ToInt16 (Console.ReadLine ());
					Console.WriteLine ("Enter point q ");
					q = Convert.ToInt16 (Console.ReadLine ());
				}
				switch (choice) {
				case 1:
					quf.union (p, q);
					break;
				case 2:
					bool b = quf.connected (p, q);
					Console.WriteLine ("Are both points connected ?");
					Console.WriteLine (b.ToString ());
					break;
				default:
					break;
				}

			}
			Console.ReadLine ();
		}