private IEnumerable <Ride> GetBestScore(int n) { var comparer = Ride.CreateScoreComparer(_car, _problem); var heap = new MinHeap <Ride>(comparer); foreach (var ride in _availableRides) { if (_car.CanMakeIt(ride) && (heap.Count < n || comparer.Compare(heap.Min, ride) < 0)) { heap.Add(ride); if (heap.Count > n) { heap.ExtractMin(); } } } return(heap); }
/// <summary> /// Extract the largest element. /// </summary> /// <exception cref="InvalidOperationException"></exception> public T ExtractMax() => minHeap.ExtractMin();