所有顶点间最短路径FloydWarshall算法主例程C++

来源:互联网 发布:淘宝图片轮播尺寸大小 编辑:程序博客网 时间:2024/04/26 18:03

   这个东西,是新学的.上一本书虽然有学过图,但是,这个问题还是没有学到,这一次,学到了.前前后后2天,写出来了.

  最近的主要精力在C++与<<Windows via>> 还有 线性代数,算法的东西实在是前进得不多.

  还好,通过今天上午的努力,知道自己的脑袋,还没有退化.真的,每次实现了一个算法,都兴奋得不得了,确实啊,呵呵.

//graph.cpp#include "stdafx.h"#include "graphRepresentAsAdjacentMatrix.h"#include <iostream>#include <vector>const int Size = 5 ;using std ::vector ;int _tmain(int argc, _TCHAR* argv[]){Graph g(Size) ;vector<int> indexVector ;vector<int> weightVector ;indexVector.push_back(1) ;indexVector.push_back(2) ;indexVector.push_back(4) ;weightVector.push_back(3) ;weightVector.push_back(8) ;weightVector.push_back(-4) ;g.importARowOfGraph(indexVector, weightVector) ;//0indexVector.erase(indexVector.begin(), indexVector.end()) ;weightVector.erase(weightVector.begin(), weightVector.end()) ;indexVector.push_back(3) ;indexVector.push_back(4) ;weightVector.push_back(1) ;weightVector.push_back(7) ;g.importARowOfGraph(indexVector, weightVector) ;//1indexVector.erase(indexVector.begin(), indexVector.end()) ;weightVector.erase(weightVector.begin(), weightVector.end()) ;indexVector.push_back(1) ;weightVector.push_back(4) ;g.importARowOfGraph(indexVector, weightVector) ;//2indexVector.erase(indexVector.begin(), indexVector.end()) ;weightVector.erase(weightVector.begin(), weightVector.end()) ;indexVector.push_back(0) ;indexVector.push_back(2) ;weightVector.push_back(2) ;weightVector.push_back(-5) ;g.importARowOfGraph(indexVector, weightVector) ;//3indexVector.erase(indexVector.begin(), indexVector.end()) ;weightVector.erase(weightVector.begin(), weightVector.end()) ;indexVector.push_back(3) ;weightVector.push_back(6) ;g.importARowOfGraph(indexVector, weightVector) ;//4indexVector.erase(indexVector.begin(), indexVector.end()) ;weightVector.erase(weightVector.begin(), weightVector.end()) ;g.floydWarshall() ;g.printPathBetweenTwoVertexes(2, 4) ;std ::cin.get() ;return 0 ;}
原创粉丝点击