static void Main(string[] args) { AvlTree <int> tree = new AvlTree <int>(); tree.Add(30); tree.Add(91); tree.Add(19); tree.Add(76); tree.Add(40); tree.Add(71); tree.Add(8); tree.Add(99); tree.Add(90); tree.Add(21); tree.Remove(21); tree.Remove(30); tree.Remove(99); tree.Remove(71); tree.Remove(40); tree.Remove(8); tree.Remove(91); tree.Remove(19); tree.Remove(76); tree.Remove(90); }
static void Main(string[] args) { var tree = new AvlTree <Bit>(); // Insert tree.Insert(new Bit(8)); tree.Insert(new Bit(7)); tree.Insert(new Bit(6)); tree.Insert(new Bit(5)); tree.Insert(new Bit(4)); tree.Insert(new Bit(3)); tree.Insert(new Bit(2)); tree.Insert(new Bit(1)); // Remove tree.Remove(new Bit(4)); // Find var result = tree.Find(new Bit(2)); }
static void Main(string[] args) { AvlTree tree = new AvlTree(); string line; string[] words; string command; Console.Write(">>"); while ((line = Console.ReadLine()) != null && line != "") { words = line.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); if (words.Length > 0) { command = words[0]; switch (command) { case "+": for (int i = 2; i < words.Length; i += 2) { int value; if (int.TryParse(words[i], out value)) { tree.Add(words[i - 1], value); } } Console.WriteLine(); break; case "-": for (int i = 1; i < words.Length; i++) { tree.Remove(words[i]); } break; case "save": if (words.Length > 1) { tree.SaveToFile(words[1]); } break; case "load": if (words.Length > 1) { tree.LoadFromFile(words[1]); } break; case "search": if (words.Length > 1) { int value; Console.WriteLine(tree.Search(words[1], out value) ? $"\nValue found: {value}" : "\nNot found\n"); } break; case "output": tree.Output(); break; case "clear": tree.Clear(); break; default: Console.WriteLine("\nThere is no such command.\n"); break; } } Console.Write("\n>>"); } }