public DijkstraSP(EdgeWeightedDigrap graph, int s) { distTo = new double[graph.V]; edgeTo = new DirectedEdge[graph.V]; minPq = new IndexMinPq<double>(graph.V); for (int i = 0; i < graph.V; i++) { distTo[i] = Double.MaxValue; } distTo[s] = 0; minPq.Insert(0, 0); while (!minPq.IsEmpty()) { Visit(graph, minPq.DelMin()); } }
public PrimMST(EdgeWeightedGraph graph) { edgeTo = new Edge[graph.V]; diestTo = new double[graph.V]; marked = new bool[graph.V]; for (int v = 0; v < graph.V; v++) { diestTo[v] = double.MaxValue; } pq = new IndexMinPq<double>(graph.V); diestTo[0] = 0; pq.Insert(0, 0); while (!pq.IsEmpty()) { visit(graph, pq.DelMin()); } }
public DijkstraSp(EdgeWeightedDigraph graph, int source) { _edgeTo = new Dictionary <int, DirectedEdge>(); _distanceTo = new Dictionary <int, double>(); _queue = new IndexMinPq <double>(graph.Vertices().Length); foreach (var vertex in graph.Vertices()) { _distanceTo.Add(vertex, double.PositiveInfinity); } _distanceTo.Add(source, 0.0); _queue.Insert(source, 0.0); while (!_queue.IsEmpty()) { var vertex = _queue.DelMin(); foreach (var edge in graph.Adjacent(vertex)) { Relax(edge); } } }