graph1.h
来自「这个是我的大学作业哦 里面有些很经典的代码 出自清华大学的数据结构课本」· C头文件 代码 · 共 55 行
H
55 行
#ifndef GRAPH1_H
#define GRAPH1_H
//****************
#include<iostream>
using namespace std;
//***********************
const int DefaultSize = 6;
template <class NameType, class DistType> class Graph;
//------------------------------------------------------------
template <class DistType> class Edge {
friend class Graph <class NameType, DistType>;
int dest;
public:
Edge<DistType> *link;
Edge(int D):dest(D),link(NULL){}
Edge<DistType> * Getlink(){return link;}
void Value(int S){dest = S;}
int Getdest(){return dest;}
};
//--------------------------------------------------------
template <class NameType,class DistType> class Vertex {
friend class Graph <NameType, DistType>;
friend class Edge <DistType>;
NameType data;
Edge<DistType> *adj;
public:
Vertex():adj(NULL){};
};
//--------------------------------------------------------------
template <class NameType,class DistType> class Graph {
Vertex <NameType,DistType> * NodeTable;
int *count1;
int *count2;
int NumVertex;
int NumEdge;
int GetVertexPos(const NameType &vertex);
void DFS(int v,int visited[]);
public:
Graph(int sz);
void InsertVertex(NameType & vertex);
void InsertEdge(int v1,int v2);
void Count();
int GetFirstNeighbor(int v);
int GetNextNeighbor(int v1,int v2);
void DFS();
void BFS(int v);
void TopologicalSort();
};
#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?