📄 exam8-4.cpp
字号:
#include <iostream.h>
#include <stdlib.h>
typedef char VerT;
typedef char DataType;
const int MaxVertices = 100;
const int MaxWeight = 9999;
#include "AdjMWGraph.h"
#include "Dijkstra.h"
#include "CreatAdjMWGraph.h"
void main(void)
{
AdjMWGraph g;
char a[] = {'A','B','C','D','E','F'};
RowColWeight rcw[] = {{0,2,5},{0,3,30},{1,0,2},{1,4,8},{2,1,15},{2,5,7},
{4,3,4},{5,3,10},{5,4,18}};
int n = 6, e = 9;
CreatGraph(g, a, n, rcw, e);
int *distance = new int[n];
int *path = new int[n];
Dijkstra(g, 0, distance, path);
cout << "从顶点A到其它各顶点的最短距离为:" << endl;
for(int i = 1; i < n; i++)
cout << "到顶点 " << g.GetValue(i)
<< " 的最短距离为:" << distance[i] << endl;
cout << "从顶点A到其它各顶点的前一顶点分别为:" << endl;
for(i = 0; i < n; i++)
if(path[i] != -1)
cout << "到顶点 " << g.GetValue(i)
<< " 的前一顶点为 " << g.GetValue(path[i]) << endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -