Min Heap (Implementation)
You will implement a min heap in this lesson.
Implementation
Now that all the functions of a min heap have been discussed, they have been implemented in the following code executable. Run and test the code on multiple outputs to see if it returns the elements in the correct order every time. Try it!
Press + to interact
C#
Files
using System;namespace chapter_8{class Program{static void Main(string[] args){MinHeap<int> heap = new MinHeap<int>();int size = 6;int[] arr = { 2, 8, 15, 5, 1, 20 };heap.buildHeap(arr, size);heap.printHeap();Console.WriteLine(heap.getMin());heap.removeMin();Console.WriteLine(heap.getMin());heap.removeMin();heap.insert(-10);Console.WriteLine(heap.getMin());return;}}}
...
Access this course and 1400+ top-rated courses and projects.