资源简介
最短路径算法Dijkstra源代码,测试可以正常使用

代码片段和文件信息
//dijkstra
#include
#include
using namespace std;
const int maxn = 3100;
char mystr[200];
int nmstartovercost[maxn][maxn]dist[maxn]used[maxn]way[maxn];
//////////////////////////////////
void print(int a) //递归打印
{
if (way[a]!=-1)
print(way[a]);
cout << a<< “\t“;
}
///////////////////////////
int main(void)
{
//init
int ijkabcmin;
freopen(“dijk.in““r“stdin);
freopen(“dijk.out““w“stdout);
// freopen( “CON“ “w“ stdout ); 恢复屏幕输出
// cout<<“input: node num start node end node“< cin >> n >> start >> over ;
for (i = 1; i <= n; i++)
{
for (j = 1; j <= n; j++)
cost[i][j] = 0x7FFFFFFFL;
cost[i][i] = 0;
}
while (!feof(stdin))
{
mystr[0] = ‘\0‘;
gets(mystr);
if (strlen(mystr) != 0)
{
sscanf(mystr “%d%d%d“ &a &b &c);
cost[a][b] = c;
cost[b][a] = c;
}
}
for (i = 1;i <= n;i++)
{
dist[i] = cost[start][i];
used[i] = 0;
way[i] = start;
}
//dijkstra
used[start] = 1;
for (i = 1; i < n; i++)
{
min = 0x7FFFFFFFL;
for (j = 1; j <= n; j++)
{
if (dist[j] < min && used[j] == 0)
{
min = dist[j];
k = j;
} // 确定下一个搜索起始的结点
}
used[k] = 1;
for (j = 1; j <= n; j++)
{
if (min + cost[k][j] < dist[j] && cost[k][j] < 0x7FFFFFFFL)
{
dist[j] = min + cost[k][j];
way[j] = k;
}
}
} //for
//out
cout << dist[over] << “\t“;
way[start] = -1;
print(over);
return 0;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 9024 2016-06-22 16:37 Dijkstra_test\Debug\BuildLog.htm
文件 43247 2016-06-22 16:37 Dijkstra_test\Debug\dijkstra.obj
文件 44032 2016-06-22 16:37 Dijkstra_test\Debug\Dijkstra_test.exe
文件 663 2016-06-22 15:31 Dijkstra_test\Debug\Dijkstra_test.exe.em
文件 728 2016-06-22 15:31 Dijkstra_test\Debug\Dijkstra_test.exe.em
文件 621 2016-06-22 16:37 Dijkstra_test\Debug\Dijkstra_test.exe.intermediate.manifest
文件 433800 2016-06-22 16:37 Dijkstra_test\Debug\Dijkstra_test.ilk
文件 560128 2016-06-22 16:37 Dijkstra_test\Debug\Dijkstra_test.pdb
文件 65 2016-06-22 16:37 Dijkstra_test\Debug\mt.dep
文件 166912 2016-06-22 16:37 Dijkstra_test\Debug\vc90.idb
文件 217088 2016-06-22 16:37 Dijkstra_test\Debug\vc90.pdb
文件 70 2016-06-22 15:48 Dijkstra_test\dijk.in
文件 70 2016-06-22 15:41 Dijkstra_test\dijk.in.bak
文件 10 2016-06-22 16:37 Dijkstra_test\dijk.out
文件 1559 2016-06-22 16:40 Dijkstra_test\dijkstra.cpp
文件 1166336 2016-06-22 16:44 Dijkstra_test\Dijkstra_test.ncb
文件 891 2016-06-22 15:17 Dijkstra_test\Dijkstra_test.sln
..A..H. 8704 2016-06-22 16:44 Dijkstra_test\Dijkstra_test.suo
文件 3932 2016-06-22 15:30 Dijkstra_test\Dijkstra_test.vcproj
文件 1427 2016-06-22 16:44 Dijkstra_test\Dijkstra_test.vcproj.PC-20160614CKWE.Administrator.user
目录 0 2016-06-22 16:37 Dijkstra_test\Debug
目录 0 2016-06-22 16:40 Dijkstra_test
----------- --------- ---------- ----- ----
2659307 22
- 上一篇:编译原理消除左递归源码
- 下一篇:循环码计数器
相关资源
- Scratch源码
- E4A无障碍跨程序操作类库(带源码、
- 设备管理系统源码
- 安卓wifi直连app源码
- 我的世界源码(易语言版)
- labview编程软件滤波器以及编写程序设
- 我的界面(visual foxpro)源码
- 易语言:一键cf基址源码
- The Secret Path 3D 3D魔方迷宫[源码][scra
- scratch垃圾分类源码(最终版本).sb
- 安卓QQ6.71协议源码易语言,qq协议源码
- 编译原理实验工具及参考源码(lex&
- E盾偷后台工具源码
- UNIX/LINUX编程实践教程的源码
- 十以内加减法练习 powerbuilder源码
- 农场开发项目
- OCR源码
- PLC上位机编程软件
- 用foobar2000听google音乐[更新一下]
- 学生信息管理系统源码
- 用VC 编写的仿QQ聊天室程序源代码
- 毕业论文之温度传感器DS18B20(源码
- 可自定义导航网站源码
- 栅栏填充算法源码(VC)
- msp430F149操作红外接收模块源码
- [免费]图像识别c 源码
- 周易排盘源码
- RSA算法源码
- 一个人脸识别程序源码
- 编译原理课程设计:词法语法编译器
评论
共有 条评论