<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->
constintMAXSIZE=50;//顶点最大数目

#include<vector>
usingnamespacestd;

template<typenameT>
classCGraph


{
public:
CGraph(void);
~CGraph(void);
private:
vector<T>vecNodes;//顶点列表
intedge[MAXSIZE][MAXSIZE];//边表
intnumVertexs;//顶点数
intnumEdges;//边数
boolvisited[MAXSIZE];//用于图的遍历

intFindVertex(constT&vertex,constvector<T>&lst);
voidClearVisitFlag();
vector<T>&GraphDepthFirstSearch(constT&beginVertex);//深度遍历图
vector<T>&GraphBreadthFirstSearch();//广度遍历

public:
boolGraphEmpty(void)const;
boolGraphFull(void)const;
intNumberOfVertices(void)const;//获取顶点数
intNumberOfEdges(void)const;//获取边数
intGetWeight(constT&vertex1,constT&vertex2);//获取指定两个顶点间的权值
vector<T>&GetNeighbors(constT&vertex);//获取指定顶点的邻接顶点

voidCreateGraph();//创建图
intGetVertexPos(constT&vertex);//获取指定顶点的位置

intInsertVertex(constT&vertex);//插入顶点
voidInsertEdge(constT&vertex1,constT&vertex2,intweight);//插入边
voidDeleteVertex(constT&vertex);//删除顶点
voidDeleteEdge(constT&vertex1,constT&vertex2);//删除边

//intMinimumPath(constT&sVertex,constT&desVertex);最短路径
voidDepthFirstSearch();//深度遍历图
voidBreadthFirstSearch();//广度遍历图
};
















































<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->



































































































































































































































































































































































































































测试程序:
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->
#include"Graph.cpp"
#include<iostream>
usingnamespacestd;


intmain(intargc,char*argv[])


{

CGraph<int>*graph1=newCGraph<int>();
graph1->CreateGraph();
graph1->DepthFirstSearch();
graph1->BreadthFirstSearch();
system("pause");
return0;
}

















