...

/

Min Heap (Implementation)

Min Heap (Implementation)

You will implement a min heap in this lesson.

We'll cover the following...

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
main.cs
MinHeap.cs
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;
}
}
}
...