[go: nahoru, domu]

Skip to content

Commit

Permalink
普利姆算法添加注释
Browse files Browse the repository at this point in the history
  • Loading branch information
rmzf9192 committed Dec 25, 2019
1 parent f1a45cc commit f89a426
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/main/java/com/el/jichu/algorithm/prim/PrimAlgorithm.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,15 @@ public void prim(MGraph graph,int v){
//将minWeight设置为较大值,在后面遍历时,会被替换
int minWeight = 10000;

//根据普利姆算法知,根据verxs得到graph.verxs - 1条边
for (int k = 1; k < graph.verxs; k++) {
//根据普利姆算法知,根据verxs得到graph.verxs - 1条边

for (int i = 0; i < graph.verxs; i++) {
//确定每生成一个子图,所得到的边的值最小
for (int j = 0; j < graph.verxs; j++) {
//确定每生成一个子图,和那个节点的距离最小
for (int i = 0; i < graph.verxs; i++) {//i节点表示被访问过的节点

for (int j = 0; j < graph.verxs; j++) {//j节点表示未访问过的节点
if(visited[i] == 1 && visited[j] == 0 && graph.weight[i][j] < minWeight){
//替换minWeight(寻找已经访问的节点与未被访问的节点的权值的最小边)
minWeight = graph.weight[i][j];
h1 = i;
h2 = j;
Expand Down

0 comments on commit f89a426

Please sign in to comment.