void dijkstra(Graph g,int s){
Heap pq = new Heap();
int v,w;
pq.enQueue(s);
for(int i = 0;i<G.vertexCount;i++){
Distance[i] = -1;
}
Distance[s] = 0;
while(!pq.isEmpty()){
int v = pq.deleteMin();
for(int j =0;j< G.vertexCount;j++){
if(adjMatrix[v][j] == 1){
int d = Distance[v] + weight[v][j];
if(Distance[j] == -1){
Distance[j] = d;
pq.enQueue(j);
Path[j] = v;
}
if(Distance[j] > d){
Distance[j] = d;
Path[j] = v;
}
}
}
}
}
有权图最短路径JAVA
最新推荐文章于 2023-04-08 23:27:52 发布