Finish Tarjan algorithm and add tests
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
#ifndef GRAPH_H_
|
||||
#define GRAPH_H_
|
||||
|
||||
#include "vertex.h"
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
namespace graph {
|
||||
|
||||
@@ -16,50 +15,44 @@ public:
|
||||
Graph() = default;
|
||||
|
||||
// Add vertex v
|
||||
void insert(Vertex<T>& v);
|
||||
void insert(const T& v);
|
||||
|
||||
// Add edge between v and u
|
||||
void insert(Vertex<T> v, Vertex<T> u);
|
||||
void insert(const T& v, const T& u);
|
||||
|
||||
// Delete vertex v
|
||||
void erase(Vertex<T>& v);
|
||||
void erase(T& v);
|
||||
|
||||
// Delete edge between v and u
|
||||
void erase(Vertex<T>& v, Vertex<T>& u);
|
||||
|
||||
// Return true if v and u are connected
|
||||
bool connected(const Vertex<T>& v, const Vertex<T>& u) const;
|
||||
void erase(T& v, T& u);
|
||||
|
||||
// Adjacency matrix representation
|
||||
std::vector<Vertex<T>> vertices;
|
||||
std::set<T> vertices;
|
||||
std::map<T, std::vector<T>> adjMatrix;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
inline void Graph<T>::insert(Vertex<T>& v) {
|
||||
vertices.push_back(v);
|
||||
inline void Graph<T>::insert(const T& v) {
|
||||
vertices.insert(v);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void Graph<T>::insert(Vertex<T> v, Vertex<T> u) {
|
||||
v.edges.push_back(u);
|
||||
vertices.push_back(v);
|
||||
inline void Graph<T>::insert(const T& v, const T& u) {
|
||||
vertices.insert(v);
|
||||
vertices.insert(u);
|
||||
adjMatrix[v].push_back(u);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void Graph<T>::erase(Vertex<T>& v) {
|
||||
inline void Graph<T>::erase(T& v) {
|
||||
//
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void Graph<T>::erase(Vertex<T>& v, Vertex<T>& u) {
|
||||
inline void Graph<T>::erase(T& v, T& u) {
|
||||
//
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline bool Graph<T>::connected(const Vertex<T>& v, const Vertex<T>& u) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace graph
|
||||
|
||||
#endif
|
||||
@@ -1,36 +0,0 @@
|
||||
#ifndef VERTEX_H_
|
||||
#define VERTEX_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <compare>
|
||||
#include <ostream>
|
||||
#include <vector>
|
||||
|
||||
namespace graph {
|
||||
|
||||
template<typename T>
|
||||
class Vertex {
|
||||
public:
|
||||
Vertex() = default;
|
||||
Vertex(T v) : v(v) {}
|
||||
|
||||
T v;
|
||||
std::uint16_t index = -1;
|
||||
std::uint16_t lowlink = -1;
|
||||
bool onStack = false;
|
||||
std::vector<Vertex<T>> edges;
|
||||
|
||||
auto operator<=>(const Vertex&) const = default;
|
||||
|
||||
template<typename T>
|
||||
friend inline std::ostream& operator<<(std::ostream& os, const Vertex<T>& v);
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
inline std::ostream& operator<<(std::ostream& os, const Vertex<T>& vout) {
|
||||
return os << vout.v;
|
||||
}
|
||||
|
||||
} // namespace graph
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user