From 54cef5809dd3f6d4820326642de56fecc7630946 Mon Sep 17 00:00:00 2001 From: GregorSamsa42 Date: Thu, 1 Aug 2024 23:04:06 +0200 Subject: [PATCH] updated weighted_graph --- weighted_graph.cpp | 9 ++++++++- weighted_graph.h | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/weighted_graph.cpp b/weighted_graph.cpp index 68849a1..d0ad458 100644 --- a/weighted_graph.cpp +++ b/weighted_graph.cpp @@ -19,13 +19,14 @@ int Node::deg() const WeightedGraph::WeightedGraph(size_t num_nodes) : nodes(num_nodes) { - + edges = 0; } void WeightedGraph::add_edge(int from, int to, double weight) { nodes[from].add_edge(to, weight); nodes[to].add_edge(from, weight); + edges++; } std::list> WeightedGraph::adjList(int node_id) const @@ -43,6 +44,11 @@ size_t WeightedGraph::num_nodes() const return nodes.size(); } +int WeightedGraph::num_edges() const +{ + return edges; +} + std::pair WeightedGraph::min_neighbour(int node_id) const { if (adjList(node_id).empty()) @@ -82,6 +88,7 @@ WeightedGraph WeightedGraph::remove_parallel() const for (const auto& [to, weight] : lightestEdges) { G.nodes[i].add_edge(to, weight); + G.edges++; } } return G; diff --git a/weighted_graph.h b/weighted_graph.h index 1b4d4fb..2b22ae9 100644 --- a/weighted_graph.h +++ b/weighted_graph.h @@ -20,12 +20,14 @@ public: void add_edge(int from, int to, double weight); std::list> adjList(int node_id) const; size_t num_nodes() const; + int num_edges() const; int deg(int v) const; std::pair min_neighbour(int node_id) const; WeightedGraph remove_parallel() const; private: std::vector nodes; + int edges; }; #endif //C___WEIGHTEDGRAPH_H