-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraph.h
More file actions
41 lines (39 loc) · 961 Bytes
/
Graph.h
File metadata and controls
41 lines (39 loc) · 961 Bytes
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
#pragma once
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
using std::vector;
using std::queue;
using std::string;
struct Graph
{
private:
size_t mNumVertices = 0;
vector<vector<int>> mAdjacencyList;
public:
Graph();
Graph(int numVertices);
inline void addEdge(int u, int v)
{
// For performance reasons don't do any additional checks
// Caller should ensure that u and v are valid vertices
mAdjacencyList[u].push_back(v);
mAdjacencyList[v].push_back(u);
};
inline void addNode(int node_id)
{
// Basically, it just resized the adjacency list if needed
if (node_id >= mNumVertices)
{
mNumVertices = node_id + 1;
mAdjacencyList.resize(node_id + 1);
}
};
int getNumVertices() const { return mNumVertices; }
// Find the shortest path between two vertices if it exists
// Return it as a list of vertices
vector<int> getShortestPath(size_t u, size_t v);
size_t getMemoryUsage() const;
~Graph();
};