Exemplo n.º 1
0
        private static void HeapSort(MaxHeap maxHeap)
        {
            int[]      nums = new int[] { 5, 13, 2, 25, 7, 17, 20, 8, 4 };
            Heap <int> heap = new Heap <int>(nums);

            maxHeap.HeapSort(heap);
            Console.WriteLine(string.Join(',', heap.GetArray()));
        }
Exemplo n.º 2
0
        private static void Verify(MaxHeap maxHeap)
        {
            int[]      nums      = new int[] { 23, 17, 14, 6, 13, 10, 1, 5, 7, 12 };
            Heap <int> heap      = new Heap <int>(nums);
            bool       isMaxHeap = maxHeap.Verify(heap);

            Console.WriteLine($"{string.Join(',', heap.GetArray())} is max heap: {isMaxHeap}");
        }
Exemplo n.º 3
0
        private static void IncreaseKey(MaxPriorityQueue priorityQueue)
        {
            int[]      nums = new int[] { 15, 13, 9, 5, 12 };
            Heap <int> heap = new Heap <int>(nums);

            priorityQueue.IncreaseKey(heap, 4, 16);
            Console.WriteLine($"{string.Join(',', nums)} increase 4 to 16 is {string.Join(',', heap.GetArray())}");
        }
Exemplo n.º 4
0
        private static void MaxHeapify(MaxHeap maxHeap)
        {
            int[]      nums = new int[] { 27, 17, 3, 16, 13, 10, 1, 5, 7, 12, 4, 8, 9, 0 };
            Heap <int> heap = new Heap <int>(nums);

            maxHeap.MaxHeapify(heap, 3);
            Console.WriteLine($"{string.Join(',', nums)} MaxHeapify 3: {string.Join(',', heap.GetArray())} ");
        }
Exemplo n.º 5
0
        private static void BuildMaxHeap(MaxHeap maxHeap)
        {
            int[]      nums = new int[] { 5, 3, 17, 10, 84, 19, 6, 22, 9 };
            Heap <int> heap = new Heap <int>(nums);

            maxHeap.BuildMaxHeap(heap);
            Console.WriteLine($"{string.Join(',', nums)} Max Heap is: {string.Join(',', heap.GetArray())} ");
        }