Skip to content

Commit

Permalink
修了迪杰斯特拉算法的一个bug
Browse files Browse the repository at this point in the history
  • Loading branch information
BuildTools committed Jan 1, 2024
1 parent 46b26b1 commit 65b7c70
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,14 @@ void Dijkstra(Graph* g, int src) {
}
}

for (int i = 0; i < V; i++)
if (dist[i] == INT_MAX)
dist[i] = -1;

// 打印构造的最短路径
printf("Vertex Distance from Source\n");
printf("顶点\t距离\n");
for (int i = 0; i < V; i++)
printf("%d \t\t %d\n", i, dist[i]);
printf("%d\t%d\n", i, dist[i]);

// 释放动态分配的内存
free(dist);
Expand Down Expand Up @@ -427,19 +431,19 @@ int main() {

switch (choice) {
case 1:
printf("输入开始搜索的顶点索引");
printf("输入开始搜索的顶点");
scanf("%d", &startVertex);
DFS(graph, startVertex);
printf("\n\n");
break;
case 2:
printf("输入开始搜索的顶点索引");
printf("输入开始搜索的顶点");
scanf("%d", &startVertex);
BFS(graph, startVertex);
printf("\n\n");
break;
case 3:
printf("输入开始顶点的索引");
printf("输入开始顶点");
scanf("%d", &startVertex);
Prim(graph, startVertex);
break;
Expand All @@ -448,6 +452,8 @@ int main() {
printf("\n\n");
break;
case 5:
printf("输入开始顶点:");
scanf("%d", &startVertex);
Dijkstra(graph, startVertex);
printf("\n\n");
break;
Expand Down

0 comments on commit 65b7c70

Please sign in to comment.