public static void Main(string[] args) { var set = new OrderedSet<int>(); Console.WriteLine("Add numbers --> 19, 21, 55, 27, 66, 33, 17, 85"); set.Add(19); set.Add(21); set.Add(55); set.Add(27); set.Add(66); set.Add(33); set.Add(17); set.Add(85); Console.WriteLine(); Console.WriteLine("In-order print --> "); set.PrintInOrder(set.Root); Console.WriteLine(); Console.WriteLine("Foreach --> "); foreach (var item in set) { Console.Write(item + " "); } Console.WriteLine(); Console.WriteLine("EachInOrder(Action<T> action) --> "); set.EachInOrder(n => Console.Write(n + " ")); Console.WriteLine(); Console.WriteLine("Insert 44 --> "); set.Add(44); set.EachInOrder(n => Console.Write(n + " ")); Console.WriteLine(); Console.WriteLine("Remove 66 --> "); set.Remove(66); set.EachInOrder(n => Console.Write(n + " ")); Console.WriteLine(); Console.WriteLine("Find 17 --> "); var find17 = set.Find(17) != null ? "17" : "null"; Console.WriteLine(find17); Console.WriteLine(); Console.WriteLine("Find 200 --> "); var find200 = set.Find(200) != null ? "200" : "null"; Console.WriteLine(find200); Console.WriteLine(); Console.WriteLine("Contains 44 --> "); var contains44 = set.Contains(44) == true ? "true" : "false"; Console.WriteLine(contains44); Console.WriteLine(); Console.WriteLine("Contains 200 --> "); var contains200 = set.Contains(200) == true ? "true" : "false"; Console.WriteLine(contains200); Console.WriteLine(); Console.WriteLine("Count --> "); Console.WriteLine(set.Count); Console.WriteLine( "Count after Add and Remove: Add 11, Remove 55, Add 5, Add 84, Add 18, Remove 5, Remove 18 (no such value)"); set.Add(11); set.Remove(55); set.Add(5); set.Add(84); set.Add(18); set.Remove(5); set.Remove(18); Console.WriteLine("Count --> {0}", set.Count); set.EachInOrder(n => Console.Write(n + " ")); Console.WriteLine(); Console.WriteLine("Min value --> {0}", set.Min()); Console.WriteLine(); Console.WriteLine("Min value --> {0}", set.Max()); Console.WriteLine(); set.Clear(); Console.WriteLine("Clear --> {0} (Count)", set.Count); }
static void Main() { var set = new OrderedSet <int>(); Console.WriteLine("Add: 29, 11, 35, 7, 16, 23, 37, 17"); set.Add(29); set.Add(11); set.Add(35); set.Add(7); set.Add(16); set.Add(23); set.Add(37); set.Add(17); Console.WriteLine(); Console.WriteLine("In-order print: "); set.PrintInorder(set.Root); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Foreach: "); foreach (var item in set) { Console.Write(item + " "); } Console.WriteLine(); Console.WriteLine(); Console.WriteLine("EachInOrder(Action<T> action): "); set.EachInOrder(n => Console.Write(n + " ")); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Insert 23: "); set.Add(23); set.EachInOrder(n => Console.Write(n + " ")); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Remove 16: "); set.Remove(16); set.EachInOrder(n => Console.Write(n + " ")); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Find 7: "); var find7 = set.Find(7) != null ? "7" : "null"; Console.WriteLine(find7); Console.WriteLine(); Console.WriteLine("Find 200: "); var find200 = set.Find(200) != null ? "200" : "null"; Console.WriteLine(find200); Console.WriteLine(); Console.WriteLine("Contains 7: "); var contains7 = set.Contains(7) == true ? "true" : "false"; Console.WriteLine(contains7); Console.WriteLine(); Console.WriteLine("Contains 200: "); var contains200 = set.Contains(200) == true ? "true" : "false"; Console.WriteLine(contains200); Console.WriteLine(); Console.WriteLine("Count:"); Console.WriteLine(set.Count); Console.WriteLine( "Count after Add and Remove: Add 1, Remove 23, Add 5, " + "Add 14, Add 108, Remove 5, Remove 12 (no such value)"); set.Add(1); set.Remove(23); set.Add(5); set.Add(14); set.Add(108); set.Remove(5); set.Remove(12);// no such value Console.WriteLine("Count: {0}", set.Count); set.EachInOrder(n => Console.Write(n + " ")); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Min value: {0}", set.Min()); Console.WriteLine(); Console.WriteLine("Min value: {0}", set.Max()); Console.WriteLine(); set.Clear(); Console.WriteLine("Clear: {0} (Count)", set.Count); }