public void Sink(int index, IComparer <T> comparer = null) { if (comparer == null) { comparer = System.Collections.Generic.Comparer <T> .Default; } while (index < _items.Count) { int childIndex = BinaryHeapHelper.GetLeftChildIndex(index); if (childIndex >= _items.Count) { break; } int rightIndex = BinaryHeapHelper.GetRightChildIndex(index); if (rightIndex < _items.Count && _items.Less(rightIndex, childIndex, comparer)) { childIndex = rightIndex; } if (!_items.Less(childIndex, index, comparer)) { break; } _items.Swap(index, childIndex); index = childIndex; } }
public void GetLeftChildIndexTest(int index, int leftChildIndex) { var actual = BinaryHeapHelper.GetLeftChildIndex(index); Assert.Equal(leftChildIndex, actual); }