/// <summary> /// Inserts an element into the heap. /// </summary> /// <param name="item">The element to insert into the heap.</param> public void Insert(T item) { var idx = this._elements.Length; this._elements.AddLast(item); BinaryHeapUtilities.Up(this._elements.AsSpan(), idx, this._comparer); }
private T RemoveAt(int idx) { var item = this._elements[idx]; var lastItem = this._elements.RemoveLast(); if (idx < this._elements.Length) { this._elements[idx] = lastItem; BinaryHeapUtilities.Down(this._elements.AsSpan(), idx, this._comparer); } return(item); }