public DijkstraShortestPath(EdgeWeightedDigraph g, int s) { edgeTo = new DirectedEdge[g.Vcount]; distTo = new double[g.Vcount]; pq = new IndexMinPriorityQueue <double>(g.Vcount); for (int i = 0; i < g.Vcount; i++) { distTo[i] = double.PositiveInfinity; } distTo[0] = 0.0; pq.Insert(s, 0.0); while (!pq.IsEmpty()) { Relax(g, pq.DelMin()); } }
public PrimMinimumSpanTree(EdgeWeightedGraph g) { edgeTo = new Edge[g.Vcount]; distTo = new double[g.Vcount]; marked = new bool[g.Vcount]; for (int i = 0; i < g.Vcount; i++) { distTo[i] = double.PositiveInfinity; } pq = new IndexMinPriorityQueue <double>(g.Vcount); distTo[0] = 0.0; pq.Insert(0, 0.0); while (!pq.IsEmpty()) { Visit(g, pq.DelMin()); } }
public void IndexMinPrivorityQueueTest() { string[] strings1 = { "it", "was", "the", "best", "of", "times", "it", "was", "the", "worst" }; string[] strings2 = new string[strings1.Length]; Array.Copy(strings1, strings2, strings1.Length); var queue = new IndexMinPriorityQueue <string>(strings1.Length); for (int i = 0; i < strings1.Length; i++) { queue.Insert(i, strings1[i]); } Quick <string> .SimpleSort(strings2); for (int i = 0; i < strings1.Length; i++) { int index = queue.DelMin(); Assert.Equal(strings1[index], strings2[i]); } }