-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraph.hpp
49 lines (42 loc) · 1.45 KB
/
Graph.hpp
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
#ifndef GRAPH_H
#define GRAPH_H
#include "GraphBase.hpp"
using namespace std;
class Graph: public GraphBase {
//the node represents a vertex of the graph
//the node represents a linked list node with
//a pointer to the next node
class vNode {
private:
string label; //label of vertex
vNode *next; //pointer to next node
int weight; //distance of vertex
public:
//constructor used to create nodes for verteces
vNode(string l) {
label = l;
next = nullptr;
}
//constructor used to create nodes for edges
vNode(string l, int w) {
label = l;
weight = w;
next = nullptr;
}
friend class Graph; //granting the class Graph access to the node
};
//vector to store the graph in adjacency list form
vector<vNode*> adjList;
//utility vecotor to store edges of two verteces
vector<vNode> edgeList;
public:
void addVertex(std::string label);
void removeVertex(std::string label);
void addEdge(std::string label1, std::string label2, unsigned long weight);
void removeEdge(std::string label1, std::string label2);
unsigned long shortestPath(std::string startLabel, std::string endLabel, std::vector<std::string> &path);
public:
//utility method
void printAdjList();
};
#endif