Two things:
This is very important, and I wasn't able to properly declare an instance of my class without it. You have to add
<T>
after IComparable:class MinHeap<T> where T : IComparable<T>IComparable
:class MinHeap<T> where T : IComparable<T>
The suggestion of changing List
List
to IListIList
was an interesting thought. However, the reason you'd want to use List is because it automatically resizes its capacity as it grows in size. IListIList
does not have this functionality, at least from what I've read. You would want to use IListIList
if you are deriving another class from it (e.g.class MyList<T> : IList<T>
) and want to modify the behavior of the List directly.
So, my final implementation came out to this:
class MinHeap<T> where T : IComparable<T>
{
List<T> elements;
...
}
class Node : IComparable<Node>
{
...
}
void MyFunction()
{
Node currNode;
MinHeap<Node> nodeHeap = new MinHeap<Node>(1000); //Capacity
...
}