views:

69

answers:

2

Hello,

I have written the Dijkstra's algorithm many times in C++ - I need there set or priotity_queue, both give me possibility to add an element and find the least one (using specified comparator). Now, I've got a problem when trying to write Dijkstra in C# - is there any structure which could be useful for me? I need adding and finding or erasing the least element.

Using Visual Studio '08

+1  A: 

You can use mine. It is very straightforward; nothing fancy here.

http://blogs.msdn.com/ericlippert/archive/2007/10/08/path-finding-using-a-in-c-3-0-part-three.aspx

I wrote this for a simple implementation of the A* algorithm, which is a more efficient form of Dijkstra's algorithm.

Eric Lippert
Thank you, I'll do the Dijkstra using your PQ. It isn't any commercial program, just kind of extraordinary homework at high school, GPS simulator etc. Great thanks!
Wojciech
You need a DecreaseKey operation for Dijkstra, and so you need a Priority Queue that supports that.
Rubys
+2  A: 

You can use SortedSet if you use a more recent .NET Framework version.

Petar Minchev