public void Insert(T key, V value) { if (root == null) { var newNode = new NodeBST <T, V>(key, value); root = newNode; } else { Insert(root, key, value); } }
private BST <string, int> Algo(Heap <int, BST <string, int> > heap) { IComparer comparer = new StrComparer(); while (heap.Size > 1) { var bst1 = heap.ExtractMin(); var bst2 = heap.ExtractMin(); var newBst = new BST <string, int>(comparer); var key = bst1.root.Key + bst2.root.Key; var value = bst1.root.Value + bst2.root.Value; var nodeBst = new NodeBST <string, int>(key, value); nodeBst.LeftChild = bst1.root; nodeBst.RightChild = bst2.root; newBst.root = nodeBst; heap.Insert(nodeBst.Value, newBst); } return(heap.GetMin()); }
private void AddSymbol(NodeBST <T, V> node, List <(T, string, V)> symbols, string code)