话不多说,直接上代码
//--+----+----+----+----+----+----+----+----+----+----+----+----
// 没什么可说的, 除了:
// (1) 网上的代码几乎都是转来转去, 没有调试运行就直接粘过来
// (2) 以下代码结构基于电工出版社的教材(那本书读起来很难受)
// (3) 代码在Code::Blocks上测试通过, 而Ms Visual C++ 6.0无法通过
//--+----+----+----+----+----+----+----+----+----+----+----+----
#include <iostream>
#include <Windows.h>
#include <fstream>
#include <string>
using namespace std;
template<class Type>
class Graph{
friend int main();
public:
void ShortesPaths(int);
private:
int n,
*prev;
Type **c,
*dist;
};
template<class Type>
class MinHeapNode{
friend Graph<Type>;
public:
operator int ()const{return length;}
private:
int i;
Type length;
};
template<class T>
class MinHeap{
template<