-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph.h
46 lines (32 loc) · 952 Bytes
/
graph.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#ifndef GRAPH_H
#define GRAPH_H
#include<vector>
using namespace std;
enum AdjecentEdge {
ADJECENT,
NO_ADJECENT
};
//Definition for a graph
struct GraphByMatrix {
int vertexNums, edgeNums; // 顶点数 边数
vector<int> vertex; // 简单应用的话,可以省略
vector<vector<AdjecentEdge>> edges;
GraphByMatrix(): vertexNums(0), edgeNums(0),
edges(vector<vector<AdjecentEdge>>(100, vector<AdjecentEdge>(100, NO_ADJECENT))),
vertex(vector<int>(100, 0)) {}
};
struct ArcNode {
int adjvectex; // 相邻的节点 在 vertex vector中的index
ArcNode* next; // 下一个
};
struct VertexNode {
int val; // vertex data infomation
ArcNode* first;
VertexNode(int data) : val(data), first(nullptr) {}
};
struct GraphByLinkedList {
int vertexNums, edgeNums; // 顶点数 边数
vector<VertexNode*> vertex;
GraphByLinkedList(): vertexNums(0), edgeNums(0), vertex(vector<VertexNode*>(100,nullptr)) {}
};
#endif