-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraph.hpp
More file actions
44 lines (35 loc) · 1.2 KB
/
Graph.hpp
File metadata and controls
44 lines (35 loc) · 1.2 KB
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
#ifndef GRAPH_HPP
#define GRAPH_HPP
#include "GraphBase.hpp"
#include <string>
#include <vector>
class Graph : public GraphBase {
public:
Graph() = default;
~Graph() override = default;
// Abstract‐class methods
void addVertex(std::string label) override;
void removeVertex(std::string label) override;
void addEdge(std::string label1, std::string label2, unsigned long weight) override;
void removeEdge(std::string label1, std::string label2) override;
unsigned long shortestPath(std::string startLabel,
std::string endLabel,
std::vector<std::string> &path) override;
// Utility method for debugging / demo
void printGraph() const;
private:
struct Edge {
std::string dest;
unsigned long weight;
};
struct Vertex {
std::string label;
std::vector<Edge> edges;
};
std::vector<Vertex> vertices;
// Helpers
int getVertexIndex(const std::string &label) const;
bool edgeExists(const std::vector<Edge> &edges, const std::string &destLabel) const;
void removeEdgeFromList(std::vector<Edge> &edges, const std::string &destLabel);
};
#endif // GRAPH_HPP