Floyd算法c语言实现

• Q1_775903
了解作者
• 198.4KB
文件大小
• rar
文件格式
• 0
收藏次数
• VIP专享
资源类型
• 0
下载次数
• 2022-04-18 09:54
上传日期
Floyd算法，最短路径算法，c语言实现。
Floyd.rar
• Floyd
• Debug
• vc60.pdb
60KB
• Floyd.pdb
369KB
• Floyd.pch
235.8KB
• vc60.idb
41KB
• main.obj
7.6KB
• Floyd.ilk
209KB
• Floyd.exe
176.1KB
• Floyd.opt
52.5KB
• Floyd.dsw
535B
• Floyd.ncb
41KB
• main.cpp
981B
• Floyd.plg
1.2KB
• Floyd.dsp
4.2KB

#include <iostream.h> void main() { const int m = 3500; int matric[5][5] = {{0,10,m,30,100}, {m,0,50,m,m}, {m,m,0,20,10}, {m,m,20,0,60}, {m,m,m,m,0}}; int patch[5][5]; int a[5][5]; int i,j,k,pre; for (i=0; i<5; i++) { for (j=0; j<5; j++) { a[i][j] = matric[i][j]; patch[i][j] = j; } } for (k=0; k<5; k++) { for (i=0; i<5; i++) for (j=0; j<5; j++) { if(a[i][j] > a[i][k] + a[k][j]) { a[i][j] = a[i][k] + a[k][j]; patch[i][j] = patch[i][k]; } } } for (i=0; i<5; i++) for (j=0; j<5; j++) { if(a[i][j] == m) { cout<<"there is no patch form "<<i<<" to "<<j<<endl; } else { cout<<"the distance from "<<i<<" to "<<j<<" is "<<a[i][j]; cout<<" the patch is :"<<i; pre = i; do { pre = patch[pre][j]; cout<<"-- rel='nofollow' onclick='return false;'>"<<pre; }while (pre != j); cout<<endl; } } }

相关推荐