Exemplo n.º 1
0
        static void Main(string[] args)
        {
            int[] a       = new int[] { 2, 4, 5, 1, 6, 7, 8 };
            var   maxHeap = new MaxHeap(a);

            maxHeap.PrintHeap();
            a       = new int[] { 15, 72, 49, 79, 39, 3, 43, 89, 18 };
            maxHeap = new MaxHeap(a);
            maxHeap.PrintHeap();

            a = new int[] { 2, 4, 5, 1, 6, 7, 8 };
            var minHeap = new MinHeap(a);

            minHeap.PrintHeap();
            a       = new int[] { 15, 72, 49, 79, 39, 3, 43, 89, 18 };
            minHeap = new MinHeap(a);
            minHeap.PrintHeap();
        }
 public MinHeap(IEnumerable <KeyValuePair <TKey, TValue> > items, IComparer <TValue> comparer)
 {
     heap = new MinHeap <TKey, TValue, Dictionary <TKey, int> >(items, comparer);
 }
Exemplo n.º 3
0
        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);
        }