算法导论24.3章中算法的C++实现,代码如下:
/********************************************************************
* Copyright (C) 2012 Li Yachao
* Contact: liyc7711(at)gmail.com
*
* Permission to use, copy, modify, and distribute this software for
* any non-commercial purpose is hereby granted without fee, provided
* that the above copyright notice appear in all copies and that both
* that copyright notice.
* It is provided "as is" without express or implied warranty.
*********************************************************************/
#include <iostream>
using namespace std;
#define N 5 /*顶点的数目*/
#define INFINITE 0x7fffffff
//顶点结点结构
struct Vertex
{
Vertex * next;/*指向下一个顶点*/
int id;/*节点的标志*/
int weight;/*节点的权值,临界表表头到此元素上边的权值*/
Vertex():next(NULL),id(0){}
};
//图结构
struct Graph
{
Vertex *Adj[N+1];//N个顶点及邻接点头指针

博客详细介绍了《算法导论》24.3章节中的Dijkstra算法,并提供了相应的C++代码实现。
最低0.47元/天 解锁文章
2399

被折叠的 条评论
为什么被折叠?



