Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            QuickFindUF qf = new QuickFindUF(5);

            qf.Union(1, 2);
            qf.Union(3, 2);
            Console.WriteLine(qf.Conected(2, 3).ToString());
            Console.WriteLine(qf.Conected(1, 2).ToString());
        }
Ejemplo n.º 2
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            Console.WriteLine("Enter Length:");
            int         i      = Convert.ToInt32(Console.ReadLine());
            QuickFindUF quf    = new QuickFindUF(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();
        }
Ejemplo n.º 3
0
		public static void Main (string[] args)
		{
			Console.WriteLine ("Hello World!");
			Console.WriteLine ("Enter Length:");
			int i = Convert.ToInt32(Console.ReadLine());
			QuickFindUF quf = new QuickFindUF (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 ();
		}