12,450,766 members (49,475 online)

114.9K views
78 bookmarked
Posted

A Fast Priority Queue Implementation of the Dijkstra Shortest Path Algorithm

, 4 Aug 2013 CPOL
Anyone needs a fast, efficient algorithm to compute the shortest path in C#? This article provides one.
 DataStructTest Backup DataStructTest Properties DataStructTest bin Debug DataStructTest.vshost.exe.manifest Properties DataStructTest.suo _UpgradeReport_Files UpgradeReport_Minus.gif UpgradeReport_Plus.gif DataStructTest.vshost.exe DataStructTest.vshost.exe.manifest Release DataStructTest.exe obj Debug Refactor TempPE Properties.Resources.Designer.cs.dll Release TempPE DataStructTest.suo UpgradeReport_Minus.gif UpgradeReport_Plus.gif ```//by Tolga Birdal using System; using System.Collections; using System.Collections.Generic; using System.Text; namespace DataStructTest { class BasicHeap { private List InnerList = new List(); public BasicHeap() {} public int Count { get { return InnerList.Count; } } public void Push(int index, float weight) { int p = InnerList.Count, p2; InnerList.Add(new HeapNode(index,weight)); // E[p] = O do { if (p == 0) break; p2 = (p - 1) >> 1; if (InnerList[p].weight p1 && InnerList[p].weight > InnerList[p1].weight) p = p1; if (InnerList.Count > p2 && InnerList[p].weight > InnerList[p2].weight) p = p2; if (p == pn) break; HeapNode h = InnerList[p]; InnerList[p] = InnerList[pn]; InnerList[pn] = h; } while (true); return result.index; } } } ```

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

Share

 CEO Gravi Information Technologies and Consultancy Ltd Turkey
Currently, also an MSc. student in Technical University of Munich, I develop practical application in computer vision for more than 5 years. I design real-time solutions to industrial and practical vision problems, both 3D and 2D. Very interested in developing algorithms in C relating math and vision.