Exemple #1
0
        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);
        }
 public MaxHeap(IEnumerable<T> items, IComparer<T> comparer)
 {
     var negatedComparer = Comparer<T>.Create((x, y) => comparer.Compare(y, x));
     minHeap = new MinHeap<T>(items, negatedComparer);
 }