static void Main(string[] args) { Tree <int> tree = new Tree <int>(); tree.AddNode(3); tree.AddNode(5); tree.AddNode(2); tree.AddNode(1); tree.AddNode(6); tree.AddNode(7); tree.AddNode(4); tree.AddNode(5); tree.AddNode(10); tree.AddNode(6); //Console.WriteLine(tree.Root); //tree.Root.Left = new TreeNode<int>(); //Add(tree.Root.Left); //Console.WriteLine(tree.Root.Left); tree.DFS(); Console.WriteLine(); tree.BFS(); Console.WriteLine(tree.Contains(3)); }
static void Main(string[] args) { Tree tree = new Tree(); tree.AddNode(1); tree.AddNode(2); tree.AddNode(3); tree.AddNode(4); tree.ShowTree(); Console.ReadLine(); }
private static void Main(string[] args) { Console.WriteLine("Create tree..."); var tree = new Tree(); var random = new Random(); var items = new ArrayList(); for (var i = 0; i < 10; i++) { var next = random.Next(0, 100); items.Add(next); tree.AddNode(next); } var height = tree.GetHeight(tree.Root); Console.WriteLine($"Height of ({string.Join(',', items.ToArray())}): {height}"); tree.Traverse(); Console.WriteLine("Enter value for search: "); var value = Console.ReadLine(); var result = tree.Search(Convert.ToInt32(value)); Console.WriteLine(result != null ? "Found the data." : "No found."); Console.ReadLine(); }
static void Main(string[] args) { Tree <Student> Oak = new Tree <Student>(); Oak.AddNode(new Student("A", "A", 24, 2)); Console.WriteLine("1"); Oak.AddNode(new Student("B", "A", 22, 4)); Console.WriteLine("2"); Oak.AddNode(new Student("C", "A", 24, 1)); Console.WriteLine("3"); Oak.AddNode(new Student("D", "A", 24, 6)); Oak.AddNode(new Student("E", "A", 24, 34)); Oak.AddNode(new Student("F", "A", 24, 55)); Oak.AddNode(new Student("G", "A", 24, 7)); Oak.AddNode(new Student("H", "A", 24, 9)); Oak.AddNode(new Student("I", "A", 24, 11)); Oak.AddNode(new Student("J", "A", 24, 88)); var print = new TreePrint <Student>(); print.Print(Oak); Console.ReadKey(); }
static void Main(string[] args) { Tree tree = new Tree(); tree.AddNode(7); tree.AddNode(10); tree.AddNode(3); tree.AddNode(8); tree.AddNode(1); tree.AddNode(41); tree.AddNode(29); // tree.Exists(9); tree.Traverse(); Console.ReadLine(); }
static void Main(string[] args) { Tree <int> TI = new Tree <int>(); TI.AddNode(new Node_Int() { Value = 5 }); TI.AddNode(new Node_Int() { Value = 3 }); TI.AddNode(new Node_Int() { Value = 7 }); TI.AddNode(new Node_Int() { Value = 9 }); Tree <char> CharTI = new Tree <char>(); CharTI.AddNode(new Node_Char() { Value = 'a' }); CharTI.AddNode(new Node_Char() { Value = 'm' }); CharTI.AddNode(new Node_Char() { Value = 'p' }); CharTI.AddNode(new Node_Char() { Value = 'b' }); CharTI.AddNode(new Node_Char() { Value = 'q' }); Tree <string> StringTI = new Tree <string>(); StringTI.AddNode(new Node_String() { Value = "Bob" }); StringTI.AddNode(new Node_String() { Value = "Venzent" }); StringTI.AddNode(new Node_String() { Value = "Alan" }); StringTI.AddNode(new Node_String() { Value = "Riccardo" }); StringTI.AddNode(new Node_String() { Value = "Oliver" }); Console.WriteLine($"Char :{ string.Join(',', CharTI.GetAllValue(true).ToArray())}"); //Console.WriteLine("Char :" +JsonConvert.SerializeObject(CharTI.GetAllNode(true))); foreach (var item in StringTI.GetAllNode()) { Console.WriteLine($"String Value:{item.Value}"); } Console.WriteLine("Left Begin"); foreach (var item in TI.GetAllNode()) { Console.WriteLine($"Value:{item.Value}"); } Console.WriteLine("Right Begin"); foreach (var item in TI.GetAllNode(false)) { Console.WriteLine($"Value:{item.Value}"); } var searchone = TI.Search(7); Console.WriteLine($"Search Value: {searchone.Value}"); Console.ReadKey(); }