static void Main() { BST BST = new BST(); BST.Add(6); BST.Add(7); BST.Add(5); BST.Add(4); BST.Add(9); BST.Search(4); }
static void Main(string[] args) { BST bst = new BST(); bst.Add(56); bst.Add(30); bst.Add(70); bst.Add(99); bst.Add(20); Console.WriteLine(bst.Size()); Console.WriteLine(bst.Search(bst.root, 999)); }
static void TestAdd(BST <int> bst) { bst.Add(10); bst.Add(5); bst.Add(15); bst.Add(1); bst.Add(8); bst.Add(11); bst.Add(43); bst.Add(20); bst.Add(9); bst.Add(7); }
static void Main(string[] args) { solutions = new List <HashSet <int> >(); string input; List <string> inputList = new List <string>(); int n, k; while ((input = Console.ReadLine()) != null && input != "") { string[] splitString = input.Split(new char[] { ' ' }, StringSplitOptions.None); foreach (string s in splitString) { inputList.Add(s); } } n = Convert.ToInt32(inputList[0]); k = Convert.ToInt32(inputList[1]); for (int i = 2; i < inputList.Count;) { BST test = new BST(); for (int j = 0; j < k; j++, i++) { test.Add(Convert.ToInt32(inputList[i])); } CheckSolutions(test.indexes); } Console.WriteLine(solutions.Count); }
static void Main(string[] args) { BST Bst = new BST(); //SetBST(Bst); //Write("PreOrder: "); PreOrder(Bst.Root); //Write("\nInOrder: "); InOrder(Bst.Root); //Write("\nPostOrder: "); PostOrder(Bst.Root); Bst.Add(45); Bst.Add(35); Bst.Add(12); Bst.Add(5); Bst.Add(56); Bst.Add(37); Bst.Add(60); Bst.Search(70); Bst.Search(37); Bst.Remove(45); Bst.Remove(30); Bst.Remove(5); Bst.Remove(70); Bst.Remove(35); }
static public BST SetBST(BST T) { WriteLine("Girilecek veri adeti: "); int item = 0, count = ToInt32(ReadLine()); for (int i = 0; i < count; i++) { WriteLine(i + 1 + ".Veri: "); item = ToInt32(ReadLine()); T.Add(item); } return(T); }
static void Main(string[] args) { BST binarysearch = new BST(); binarysearch.Add(20); binarysearch.Add(60); binarysearch.Add(32); binarysearch.Add(70); binarysearch.Add(56); binarysearch.Add(17); binarysearch.Add(40); binarysearch.Add(12); binarysearch.Add(22); Console.WriteLine("Binary Search Tree is created"); Console.WriteLine("Please enter a number to search in the tree"); Console.ReadLine(); binarysearch.Search(binarysearch.root, 24); Console.ReadLine(); }
public static BST FromArray(BSTItem[] array) { if (array == null || array.Length == 0) { return(null); } var bst = new BST(array[0]); foreach (var i in array.Skip(1)) { bst.Add(i); } return(bst); }
static void Main(string[] args) { BST tree = new BST(); tree.Add(5); tree.Add(15); tree.Add(10); tree.Add(25); tree.Add(20); tree.Add(30); tree.Add(35); tree.Search(35); tree.Search(16); tree.Search(5); }
static void Main(string[] args) { BST tree = new BST(); tree.Add(20); tree.Add(15); tree.Add(17); tree.Add(30); tree.Add(34); tree.Add(32); tree.Add(10); tree.Add(12); CheckTree(tree); Console.WriteLine("***-*-*-*-*-*-*-***"); tree.Print(); tree.Remove(tree.GetNode(15)); CheckTree(tree); Console.WriteLine("***-*-*-*-*-*-*-***"); tree.Print(); Console.ReadLine(); }
static void Main(string[] args) { var bst = new BST(); bst.Add(12); bst.Add(14); bst.Add(7); bst.Add(7); bst.Add(18); bst.Add(3); Console.WriteLine("Hello World!"); }
static void Main(string[] args) { BST tree = new BST(); tree.Add(5); tree.Add(2); tree.Add(34); tree.Add(18); tree.Add(55); tree.Add(1); tree.Add(3); tree.Add(-1); tree.Add(-2); tree.Add(6); tree.Add(7); tree.Print(); //Console.WriteLine(tree.Search(2)); //Console.WriteLine(tree.Search(100)); //Console.WriteLine("PreOrder Traversal"); //tree.PreOrder(tree.root); //Console.WriteLine("\nInOrder Traversal"); //tree.InOrder(tree.root); //Console.WriteLine("\nPostOrder Traversal"); //tree.PostOrder(tree.root); //Console.WriteLine("\nLevelOrder Traversal"); //tree.LevelOrder(tree.root); //Console.WriteLine("\nFormat & Print LevelOrder Traversal"); //tree.LevelOrderPrint(tree.root); Console.WriteLine("\nPrint Reverse LevelOrder Traversal"); tree.LevelOrderReversePrint(tree.root); //Node minValue = tree.MinValueBST(tree.root); //Console.WriteLine("\nMin Value of BST is {0}", minValue.Data); //Node maxValue = tree.MaxValueBST(tree.root); //Console.WriteLine("\nMax Value of BST is {0}", maxValue.Data); //int heightBST = tree.HeightBST(tree.root); //Console.WriteLine("\nHeight of the BST is {0}", heightBST); //int sizeBST = tree.SizeBST(tree.root); //Console.WriteLine("\nSize of the BST is {0}", sizeBST); //Console.WriteLine("\nBefore Deleting"); //tree.Print(); //Console.WriteLine("\nAfter Deleting"); //tree.Delete(34); //tree.Print(); Console.ReadLine(); }
static void Main(string[] args) { BST myBinarySearchTree = new BST(); //TEST CASE 1: //myBinarySearchTree.Add(8); //myBinarySearchTree.Add(10); //myBinarySearchTree.Add(6); //myBinarySearchTree.Add(8); //myBinarySearchTree.Add(3); //myBinarySearchTree.Add(12); //myBinarySearchTree.Add(99); //myBinarySearchTree.Add(467); //myBinarySearchTree.Add(64); //myBinarySearchTree.Add(11); //TEST CASE 2: myBinarySearchTree.Add(127); myBinarySearchTree.Add(45); myBinarySearchTree.Add(38); myBinarySearchTree.Add(72); myBinarySearchTree.Add(117); myBinarySearchTree.Add(45); myBinarySearchTree.Add(2); myBinarySearchTree.Add(999); myBinarySearchTree.Add(50); myBinarySearchTree.Add(45); myBinarySearchTree.Add(100); Console.WriteLine(myBinarySearchTree.Search(100)); Console.ReadKey(); }
public static BST FromTable(List <Word> keys, Dictionary <int, List <Word> > keyDummies, int[][] table) { var stack = new Queue <Help>(); var rootHelp = new Help(0, table.Length - 1); stack.Enqueue(rootHelp); var rootIndex = table[rootHelp.Row][rootHelp.Column]; var rootItem = new BSTItem(keys[rootIndex]); var bst = new BST(rootItem); keys[rootIndex].Added = true; while (stack.Count != 0) { var current = stack.Dequeue(); if (current.Row > current.Column) { if (keyDummies[current.Row].Count > 0 && !keyDummies[current.Row][0].Added) { bst.Add(new BSTItem(keyDummies[current.Row])); keyDummies[current.Row][0].Added = true; } //if (current.Row < keyDummies.Count - 1) //{ // if (keyDummies[current.Row + 1].Count > 0 && !keyDummies[current.Row + 1][0].Added) // { // bst.Add(new BSTItem(keyDummies[current.Row + 1])); // keyDummies[current.Row + 1][0].Added = true; // } //} if (keyDummies[current.Column + 1].Count > 0 && !keyDummies[current.Column + 1][0].Added) { bst.Add(new BSTItem(keyDummies[current.Column + 1])); keyDummies[current.Column + 1][0].Added = true; } } else { var currentItemIndex = table[current.Row][current.Column]; stack.Enqueue(new Help(current.Row, currentItemIndex - 1)); stack.Enqueue(new Help(currentItemIndex + 1, current.Column)); if (keys[currentItemIndex].Added) { continue; } //var subBst = new BST(new BSTItem(keys[currentItemIndex])); bst.Add(new BSTItem(keys[currentItemIndex])); keys[currentItemIndex].Added = true; //if (current.Row == current.Column) //{ // subBst.Add(new BSTItem(keyDummies[currentItemIndex])); // subBst.Add(new BSTItem(keyDummies[currentItemIndex + 1])); //} } } return(bst); }