42 lines
678 B
C++
42 lines
678 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);
|
|
|
|
// 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);
|
|
}
|
|
|
|
} // namespace graph
|
|
|
|
#endif |