public static void Execute() { var uf = new QuickFind(10); uf.Display(); uf.Union(0, 2); uf.Union(2, 3); uf.Union(2, 5); uf.Display(); Console.WriteLine($"0-5 {uf.IsConnected(0, 5)}"); Console.WriteLine($"5-3 {uf.IsConnected(5, 3)}"); Console.WriteLine($"0-7 {uf.IsConnected(0, 7)}"); Console.WriteLine($"3-8 {uf.IsConnected(3, 8)}"); }
private static void RunQuickFind() { Console.WriteLine("Quick Find:"); IUnionFind qf = new QuickFind(10); qf.Union(0, 1); qf.Union(1, 2); Console.WriteLine($"0 {(qf.Connected(1, 2) ? "is" : "is not")} connected with 2"); Console.WriteLine($"0 {(qf.Connected(0, 9) ? "is" : "is not")} connected with 9"); qf.Union(2, 8); qf.Union(9, 8); Console.WriteLine($"0 {(qf.Connected(0, 9) ? "is" : "is not")} connected with 9"); Console.WriteLine($"Max element for component containg 2 is {qf.Find(2)}"); Console.WriteLine($"Max element for component containg 3 is {qf.Find(3)}"); qf.Union(0, 3); qf.Union(0, 4); qf.Union(2, 5); qf.Union(6, 9); qf.Union(1, 7); }