37 lines
943 B
C++
37 lines
943 B
C++
#ifndef C___WEIGHTEDGRAPH_H
|
|
#define C___WEIGHTEDGRAPH_H
|
|
|
|
#include <list>
|
|
#include <vector>
|
|
#include <algorithm>
|
|
|
|
|
|
struct Node {
|
|
// todo: introduce neighbor struct and use it instead of std::pair
|
|
std::list<std::pair<int, double>> neighbours;
|
|
Node() = default;
|
|
explicit Node(std::list<std::pair<int, double>> neighbours);
|
|
void add_edge(int node_id, double weight);
|
|
[[nodiscard]] int deg() const;
|
|
};
|
|
|
|
class WeightedGraph {
|
|
public:
|
|
explicit WeightedGraph(size_t num_nodes);
|
|
void add_edge(int from, int to, double weight);
|
|
[[nodiscard]] std::list<std::pair<int, double>> adjList(int node_id) const;
|
|
[[nodiscard]] size_t num_nodes() const;
|
|
[[nodiscard]] int num_edges() const;
|
|
[[nodiscard]] int deg(int v) const;
|
|
[[nodiscard]] std::pair<int,double> min_neighbour(int node_id) const;
|
|
[[nodiscard]] WeightedGraph remove_parallel() const;
|
|
|
|
private:
|
|
std::vector<Node> nodes;
|
|
int edges;
|
|
};
|
|
|
|
#endif //C___WEIGHTEDGRAPH_H
|
|
|
|
|