算法导论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个顶点及邻接点头指针
int p[N&