static void Main(string[] args) { BinarySearchTree t = new BinarySearchTree(); t.Add(2); t.Add(7); t.Add(9); t.Add(10); t.Add(1); t.Add(5); t.Add(16); t.Add(19); t.Add(8); t.Add(4); t.TraverseInOrder(); Console.WriteLine(); t.ToString(); }
static void Main(string[] args) { BinarySearchTree test = new BinarySearchTree(); Node elderRoot = test.AddElement(5); test.InsertElement(test.CurrentParrent, elderRoot); test.InsertElement(test.CurrentParrent, test.AddElement(6)); test.InsertElement(test.CurrentParrent, test.AddElement(10)); test.InsertElement(test.CurrentParrent, test.AddElement(1)); test.InsertElement(test.CurrentParrent, test.AddElement(15)); test.InsertElement(test.CurrentParrent, test.AddElement(2)); test.InsertElement(test.CurrentParrent, test.AddElement(3)); test.InsertElement(test.CurrentParrent, test.AddElement(12321)); test.InsertElement(test.CurrentParrent, test.AddElement(61)); test.InsertElement(test.CurrentParrent, test.AddElement(90)); test.InsertElement(test.CurrentParrent, test.AddElement(0)); test.InsertElement(test.CurrentParrent, test.AddElement(-5)); test.InsertElement(test.CurrentParrent, test.AddElement(-123)); BinarySearchTree ff = (BinarySearchTree)test.Clone(); Console.WriteLine(ff); }
static void Main(string[] args) { BinarySearchTree MyBST = new BinarySearchTree(); }
public void Initialize() { tree = new BinarySearchTree<int>(); }
//----------------------------------- // balancing the binary tree // after the tree has been built // // WARNING! This code has not been checked... // and you may need to change it // depending on your tree design //------------------------------------ public void balance(BinaryTreeNode node) { if (node == null) { } if (node != null) { BinarySearchTree tree = new BinarySearchTree(); if (node.RightChild.level - node.LeftChild.level > 1) { if (node.RightChild.level > node.LeftChild.level) { node = rotateL(node); node = rotateR(node); } else { node = rotateL(node); } } else { if (node.LeftChild.level > node.RightChild.level) { node = rotateR(node); node = rotateL(node); } else { node = rotateR(node); } } balance(node.LeftChild); balance(node.RightChild); } }
public override void ViewDidLoad() { base.ViewDidLoad (); tempLabelCount = 0; sizeOftheLabels = new CGSize (25, 25); LabelSpace = new CGSize (25,35); myNodalArray = new BinarySearchTree(); lbl1.Layer.MasksToBounds = true; lbl1.Layer.CornerRadius = 5.0f; lbl1.UserInteractionEnabled = true; lbl2.Layer.MasksToBounds = true; lbl2.Layer.CornerRadius = 5.0f; lbl3.Layer.MasksToBounds = true; lbl3.Layer.CornerRadius = 5.0f; lbl4.Layer.MasksToBounds = true; lbl4.Layer.CornerRadius = 5.0f; lbl5.Layer.MasksToBounds = true; lbl5.Layer.CornerRadius = 5.0f; myScroll = new UIScrollView (MyNodalView.Frame); myScroll.ContentSize = new CGSize (LabelSpace.Width * (Math.Pow (2, myNodalArray.level)),myNodalArray.level * LabelSpace.Height); MyNodalView.Add (myScroll); GenButton.TouchUpInside += GenButton_TouchUpInside; CreateTree.TouchUpInside += CreateTree_TouchUpInside; }
public override void ViewDidLoad() { base.ViewDidLoad (); tempLabelCount = 0; myNodalArray = new BinarySearchTree(); lbl1.Layer.MasksToBounds = true; lbl1.Layer.CornerRadius = 5.0f; lbl1.UserInteractionEnabled = true; lbl2.Layer.MasksToBounds = true; lbl2.Layer.CornerRadius = 5.0f; lbl3.Layer.MasksToBounds = true; lbl3.Layer.CornerRadius = 5.0f; lbl4.Layer.MasksToBounds = true; lbl4.Layer.CornerRadius = 5.0f; lbl5.Layer.MasksToBounds = true; lbl5.Layer.CornerRadius = 5.0f; GenButton.TouchUpInside += GenButton_TouchUpInside; }
static void Main(string[] args) { BinarySearchTree bt = new BinarySearchTree(); int choice, x; while (true) { Console.WriteLine(" 1. Display Tree"); Console.WriteLine(" 2. Search"); Console.WriteLine(" 3. Insert a new node"); Console.WriteLine(" 4. Delete a node"); Console.WriteLine(" 5. Preorder Traversal"); Console.WriteLine(" 6. Inorder Traversal"); Console.WriteLine(" 7. Postorder Traversal"); Console.WriteLine(" 8. Height of tree"); Console.WriteLine(" 9. Find Minimum key"); Console.WriteLine("10. Find Maximum key"); Console.WriteLine("11. Quit"); Console.WriteLine("Enter your choice : "); choice = Convert.ToInt32(Console.ReadLine()); if (choice == 11) { break; } switch (choice) { case 1: bt.Display(); break; case 2: Console.Write("Enter the key to be searched : "); x = Convert.ToInt32(Console.ReadLine()); if (bt.Search(x)) { Console.WriteLine("Key found"); } else { Console.WriteLine("Key not found"); } break; case 3: Console.Write("Enter the key to be inserted : "); x = Convert.ToInt32(Console.ReadLine()); bt.Insert(x); break; case 4: Console.Write("Enter the key to be deleted : "); x = Convert.ToInt32(Console.ReadLine()); bt.Delete(x); break; case 5: bt.Preorder(); break; case 6: bt.Inorder(); break; case 7: bt.Postorder(); break; case 8: Console.WriteLine("Height of tree is " + bt.Height()); break; case 9: Console.WriteLine("Minimum key is " + bt.Min()); break; case 10: Console.WriteLine("Maximum key is " + bt.Max()); break; } } }