static void CallFind(DisjointSet ds) { Console.WriteLine("\nFind"); Console.Write("Input: "); string input = Console.ReadLine(); int element = Convert.ToInt32(input); Console.WriteLine("Root: {0}", ds.Find(element)); }
static void CallUnion(DisjointSet ds) { Console.WriteLine("\nUnion"); Console.Write("Input e1: "); string input = Console.ReadLine(); int e1 = Convert.ToInt32(input); Console.Write("Input e2: "); input = Console.ReadLine(); int e2 = Convert.ToInt32(input); int r1 = ds.Find(e1); int r2 = ds.Find(e2); if (r1 == r2) { Console.WriteLine($"Error: {e1} and {e2} are in the same set {r1}"); return; } ds.Union(r1, r2); }
static void Main(string[] args) { var set = new DisjointSet(); set.Make(5); set.Make(3); set.Make(1); set.Make(7); set.Make(4); set.Union(5, 3); set.Union(2, 1); set.Union(3, 4); Console.WriteLine(set.Find(4)); Console.WriteLine("Press any key..."); Console.ReadKey(); }