graph-algorithms/weighted_graph.h

36 lines
758 B
C
Raw Normal View History

2024-07-30 18:16:33 +02:00
#ifndef C___WEIGHTEDGRAPH_H
#define C___WEIGHTEDGRAPH_H
#include <list>
#include <vector>
#include <algorithm>
struct Node {
std::list<std::pair<int, double>> neighbours;
Node() = default;
Node(std::list<std::pair<int, double>> neighbours);
void add_edge(int node_id, double weight);
int deg() const;
};
class WeightedGraph {
public:
WeightedGraph(size_t num_nodes);
void add_edge(int from, int to, double weight);
std::list<std::pair<int, double>> adjList(int node_id) const;
size_t num_nodes() const;
2024-08-01 23:04:06 +02:00
int num_edges() const;
2024-07-30 18:16:33 +02:00
int deg(int v) const;
std::pair<int,double> min_neighbour(int node_id) const;
WeightedGraph remove_parallel() const;
private:
std::vector<Node> nodes;
2024-08-01 23:04:06 +02:00
int edges;
2024-07-30 18:16:33 +02:00
};
#endif //C___WEIGHTEDGRAPH_H