floydp1.cpp

来自「用vc++编写的关于数据结构的图类的若干算法」· C++ 代码 · 共 33 行

CPP
33
字号
//FloydP1.cpp
#include<iostream.h>
#include<iomanip.h>
#include<stdlib.h>
#include "graph.cpp"
#include "FloydP.h"
//弗洛伊德算法测试
void main()
{cout<<"FloydP1.cpp运行结果:\n";
 int n=6,k1=1,k2=1,i,j;
 AdjMatrix g(n,k2);
 g.CreateMatrix(n,k1,k2);
 cout<<"输出邻接矩阵相应图的顶点:\n";
 g.Creatgraph(n,k2);
 
 int m=g.NumV();
 int dist[6][6],path[6][6];
 Floyd(g,dist,path);
 for(i=0;i<m;i++)
 {cout<<"从顶点"<<g.GetValue(i)
      <<"到其他各顶点的最短距离为:\n";
  for(j=0;j<m;j++)
   cout<<"到顶点"<<g.GetValue(j)
       <<"的最短距离为:"<<dist[i][j]<<endl;
   cout<<"从顶点"<<g.GetValue(i)
       <<"到其他各顶点的最短路径的前一顶点为:\n";
   for(j=0;j<m;j++)
    if(path[i][j]!=-1)
     cout<<"到顶点"<<g.GetValue(j)<<"的前一顶点为:"
         <<g.GetValue(path[i][j])<<endl;
 }
 cin.get();cin.get();}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?