-
Notifications
You must be signed in to change notification settings - Fork 0
/
Graph.h
46 lines (29 loc) · 824 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>
// implement graph via adjacent matrix
class Graph
{
public:
Graph() {}
Graph(int verticeNum);
Graph(int verticeNum, double density);
int getVerticeNum() const { return verticeNum; }
int getEdgeNum() const { return edgeNum; }
// tests whether there is an edge from node x to node y
bool adjacent(int x, int y) const;
// lists all nodes y such that there is an edge from
// x to y
std::vector<int> neighbors(int x) const;
// return all vertices in the graph
std::vector<int> getVertices() const;
bool addEdge(int x, int y, int value);
bool deleteEdge(int x, int y);
int getEdgeValue(int x, int y) const;
void setEdgeValue(int x, int y, int value);
private:
int edgeNum;
int verticeNum;
std::vector<std::vector<int> > adMatrix;
};
#endif