Exemple #1
0
        public void ExtractMinBubbleRight()
        {
            var data    = new[] { 13, 5, 9, 2, 1, 4, 8 };
            var maxHeap = new Heap <int>((p, c) => p > c);

            maxHeap.AddAll(data);
            Assert.AreEqual(13, maxHeap.ExtractMin());
            Assert.AreEqual(9, maxHeap.ExtractMin());
            Assert.AreEqual(8, maxHeap.ExtractMin());
        }
Exemple #2
0
        public static void MaxHeapSort()
        {
            int[]      collection = new[] { 1, 2, 3, 4, 5 };
            Heap <int> minHeap    = new Heap <int>((p, c) => p > c);

            minHeap.AddAll(collection);

            int[] sorted = new[] { 5, 4, 3, 2, 1 };
            for (int i = 0; i < sorted.Length; i++)
            {
                Assert.AreEqual(sorted[i], minHeap.ExtractMin());
            }
        }