老样子,跟着算法导论走.
// graphRepresentAsAdjacentList.h -- graph header file.
// 2011-09-02-19.38 -- 2011-09-02-21.47
// Purpose:
// Define a class "graphRepresentAsAdjacentList".
// Declare methods of the class, and define element member.
#include <iostream>
#include <vector>
using std ::vector ;
class graphRepresentAsAdjacentList
{
public:
typedef struct vertex
{
int indexInAdjacentList ;
int weight ;
struct vertex * next ;
} Vertex ;
static const int Infinity = 1 << 30 ;
static const int Nil = -1 ;
private:
int m_size ;
int m_currentSize ;
vector<Vertex> m_adjacentListVector ;
vector<int> m_parentVector ;
vector<int> m_distanceVector ;
Vertex * m_makeVertex (int indexInAdjacentList, int weight) ;
void m_initializeSingleSource (int sourceVertex) ;
int m_distanceBetweenTwoVertexes (int startVertex, int endVertex) ;
void m_relax (int startVertex, int endVertex) ;
public:
graphRepresentAsAdjacentList (int size = 0) ;
~graphRepresentAsAdjacentList (void) ;
bool importAVertex (const std ::vector<int> & indexVector, const std ::vector<int> & weightVector) ;
bool bellmanFord (int sourceVertex) ;
void printEachShortestPathValueFromSourceVertex (int sourceVertex) ;
void printGraph (void) ;
} ;
// End of file.