I am implementing a generic PriorityQueue in C# as part of homework.
The items are stored in an array.
class PQueue<T> : IPQueue<T>
{
T[] items;
//..
}
How can I compare two items. I guess the type with which PQueue is instantiated has to implement IComparable/IComparer. If so, how can I compare two elements in items?
What is the elegant way to design this.
First, you need to tell C# that
<T>implementsIComparable<T>Now you can compare individual items, like this: