分支限界法解单源最短路径问题

本文介绍了如何运用分支限界法解决单源最短路径问题,通过算法设计与分析,深入探讨了该方法的有效性和实现细节。

话不多说,直接上代码

//--+----+----+----+----+----+----+----+----+----+----+----+----
// 没什么可说的, 除了:
// (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<class Type>
	friend class Graph;
	public:
		MinHeap(int maxheapsize = 10);
		~MinHeap(){delete []heap;}
		int Size
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值