How to use IPriorityQueue in the C5 Library

1.3k Views Asked by At

I am using the popular C5 library for C# (C5) and I'm trying to figure out how to implement the IPriorityQueue properly. Lets say I have the set A={5,4,1,2,3}. I want the priority to be the highest integer value. How do I implement this?

Could someone please give an example of where I add the elements in set A one by one to the queue? Where can you specify the priority property? Kinda lost on the implementation.

The ultimate goal by the way is to use this to make a binary heap.

1

There are 1 best solutions below

0
On

I'm not familiar with that C5 library, but there's an easy-to-use, high-performance priority queue implementation here:

PriorityQueue source

ConcurrentPriorityQueue source (if you need thread safety)

Using one of those, you would construct it this way:

IPriorityQueue<object> queue = new PriorityQueue<object>(5, true);

where 5 is the number of priorities you want to manage, true/false specifies whether you want the priorities to be considered to be descending or ascending in priority, and <object> would be your generic type. Both of these support full list operations as well. There's also a project website.