用了类模板,不知是不是多此一举,反正练习为主.
// graphRepresentAsAdjacentMatrix.h -- graph header file.
// Purpose:
// A graph represent as a adjacent matrix, this graph can't storage
// weight value instead of true or false means m_matrix[i][j] is on or off.
#ifndef GRAPH_H_
#define GRAPH_H_
#include <iostream>
#include <vector>
#include <queue>
using std ::vector ;
using std ::queue ;
template<class T>
class Graph
{
private:
enum Color{Color_White, Color_Gray, Color_Black} ;
static const T Infinity = 99999999 ;
unsigned int HasNotAParent ; // Set it when ctor is calling.
private:
T * * m_selectedFlow ; // Store selected flow between any two vertexes.
T * * m_residualFlow ; // Store residual flow between any two vertexes.
unsigned int * m_currentVertexAdjoinsTo ; // Store vertexes current vertex adjoins to in a increasing sequence order by residual flow.
Color * m_color ; // Store color of every vertex.
unsigned int * m_parent ; // Store each parent in the breadth first search parth.
unsigned int m_currentNumOfVertexes ;
unsigned int m_totalNumOfVertexes ;
unsigned int m_startIndex ; // It must be 0.
unsigned int m_endIndex ; // It must be m_totalNumOfVertexes - 1.
void getIncreasingOrder (unsigned int currentIndex) ;
bool m_existsAAugmentingPath (T * const pMinFlows) ;
Graph (const Graph & graph) ;
Graph & operator = (const Graph & graph) ;
public:
Graph (unsigned int numOfVertexes) ;
bool importAVertex (const vector<T> & indexAdjoinsTo, const vector<T> & residualFlowAdjoinsTo) ;
void calculateMaxFlow (void) ;
T maxFlow (void) const ;
void printEveryFlow (void) const ;
void printGraph (void) const ;
} ;
#include "Graph.cpp"
#endif