-
Notifications
You must be signed in to change notification settings - Fork 17
/
Graph.h
54 lines (42 loc) · 1.22 KB
/
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
47
48
49
50
51
52
53
54
#pragma once
#include <list>
#include <vector>
using namespace std;
class Graph
{
public:
//n is the number of vertices
//edges is a list of pairs representing the edges (default = empty list)
Graph(int n, const list< pair<int, int> > & edges = list< pair<int, int> >());
//Default constructor creates an empty graph
Graph(): n(0), m(0) {};
//Returns the number of vertices
int GetNumVertices() const { return n; };
//Returns the number of edges
int GetNumEdges() const { return m; };
//Given the edge's index, returns its endpoints as a pair
pair<int, int> GetEdge(int e) const;
//Given the endpoints, returns the index
int GetEdgeIndex(int u, int v) const;
//Adds a new vertex to the graph
void AddVertex();
//Adds a new edge to the graph
void AddEdge(int u, int v);
//Returns the adjacency list of a vertex
const list<int> & AdjList(int v) const;
//Returns the graph's adjacency matrix
const vector< vector<bool> > & AdjMat() const;
private:
//Number of vertices
int n;
//Number of edges
int m;
//Adjacency matrix
vector< vector<bool> > adjMat;
//Adjacency lists
vector< list<int> > adjList;
//Array of edges
vector< pair<int, int> > edges;
//Indices of the edges
vector< vector<int> > edgeIndex;
};