这个东西,是新学的.上一本书虽然有学过图,但是,这个问题还是没有学到,这一次,学到了.前前后后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) ; // 0
indexVector.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) ; // 1
indexVector.erase(indexVector.begin(), indexVector.end()) ;
weightVector.erase(weightVector.begin(), weightVector.end()) ;
indexVector.push_back(1) ;
weightVector.push_back(4) ;
g.importARowOfGraph(indexVector, weightVector) ; // 2
indexVector.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) ; // 3
indexVector.erase(indexVector.begin(), indexVector.end()) ;
weightVector.erase(weightVector.begin(), weightVector.end()) ;
indexVector.push_back(3) ;
weightVector.push_back(6) ;
g.importARowOfGraph(indexVector, weightVector) ; // 4
indexVector.erase(indexVector.begin(), indexVector.end()) ;
weightVector.erase(weightVector.begin(), weightVector.end()) ;
g.floydWarshall() ;
g.printPathBetweenTwoVertexes(2, 4) ;
std ::cin.get() ;
return 0 ;
}