Files
reachability-algorithms/graph/graph.h
2022-05-17 21:25:47 +03:00

50 lines
807 B
C++

#ifndef GRAPH_H_
#define GRAPH_H_
#include <map>
#include <set>
#include <utility>
#include <vector>
#include <iostream>
namespace graph {
template<typename T>
class Graph {
public:
Graph() = default;
// Add vertex v
void insert(const T& v);
// Add edge between v and u
void insert(const T& v, const T& u);
// Reverse graph directions
Graph<T> reverse();
// Adjacency matrix representation
std::set<T> vertices;
std::map<T, std::set<T>> adjMatrix;
};
template<typename T>
void Graph<T>::insert(const T& v) {
vertices.insert(v);
}
template<typename T>
void Graph<T>::insert(const T& v, const T& u) {
vertices.insert(v);
vertices.insert(u);
adjMatrix[v].insert(u);
}
template<typename T>
Graph<T> Graph<T>::reverse() {
return Graph<T>();
}
} // namespace graph
#endif