File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed
Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change 11#include < cstddef>
22#include < memory>
3+ #include < set>
34
45#include " algorithms_archive/graph/graph.h"
56
@@ -8,8 +9,16 @@ using namespace algorithms_archive::graph;
89AdjacencyMatrixGraph::AdjacencyMatrixGraph (std::size_t size)
910 : size_{size}, matrix_{std::unique_ptr<int []>{new int [size * size]}} {}
1011
11- AdjacencyMatrixGraph::AdjacencyMatrixGraph (std::initializer_list<Edge> edges)
12- : AdjacencyMatrixGraph{edges.size ()} {
12+ AdjacencyMatrixGraph::AdjacencyMatrixGraph (std::initializer_list<Edge> edges) {
13+ // count number of unique nodes in the given edges list
14+ std::set<int > nodes;
15+ for (const auto &edge : edges) {
16+ nodes.insert (edge.from .id );
17+ nodes.insert (edge.to .id );
18+ }
19+
20+ size_ = nodes.size ();
21+ matrix_ = std::unique_ptr<int []>{new int [size_ * size_]};
1322 for (const auto &edge : edges) {
1423 addEdge (edge);
1524 }
You can’t perform that action at this time.
0 commit comments