template<class T,class E>
struct Edge{
int dest;//到下個點的距離
E cost;//到下個點的權重
Edge<T,E>*link;
Edge(){}
Edge(int num,E weight):dest(num),cost(weight),link(NULL){}
};
template<class T,class E>
struct Vertex{
T data;
Edge<T,E>*adj;
}
template<class T,class E>
class Graphlnk{
public:
Graphlnk(int sz=DefaultVertices);
~Graphlnk();
T getValue(int i)
{return (i>=0&&i<NumVertices)?NodeTable[i].data:0;}
E getWeight(int v1,int v2);
bool insertVertex(const T& vertex);
bool removerVertex(int v);
bool insertEdge(int v1,int v2,E cost);
bool removeEdge(int v1,int v2);
int getFirstNeighbor(int v);
int getNextNeighbor(int v,int w);
private:
Vertex<T,E> *NodeTable;//頂點結點數組
int maxVertices;//最大頂點數
int numEdges;//邊的條數
int numVertices;//頂點的個數
};
c++中的圖鏈表數據結構
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.