/// <summary> /// Inserts the specified element into the heap at the right spot. /// </summary> /// <param name="element">The element to insert.</param> /// <remarks>It's not possible to add an element twice as this leads to problems with removal and lookup routines for elements: which node to process?</remarks> public override void Insert(TElement element) { ArgumentVerifier.CantBeNull(element, "element"); ArgumentVerifier.ShouldBeTrue(e => !this.Contains(e), element, "element to insert already exists in this heap."); FibonacciHeapNode <TElement> newNode = new FibonacciHeapNode <TElement>(element); // new element is the root of a new tree. We'll add it as the first node. newNode.BecomeTreeRoot(); _trees.InsertHead(newNode); UpdateRootIfRequired(newNode); AddElementNodeMapping(newNode); _count++; }
/// <summary> /// Converts the passed in node to a new tree in heap. /// </summary> /// <param name="elementNode">The element node.</param> private void ConvertToNewTreeInHeap(FibonacciHeapNode <TElement> elementNode) { elementNode.BecomeTreeRoot(); _trees.InsertHead(elementNode); }