From e069792410a645f82f713e579d4de91d09a7d962 Mon Sep 17 00:00:00 2001 From: Denes Matetelki Date: Wed, 27 Feb 2013 22:48:07 +0100 Subject: [PATCH] fix on numberOfEdges --- graph.h | 83 ++------------------------------------------------------ main.cpp | 1 + 2 files changed, 3 insertions(+), 81 deletions(-) diff --git a/graph.h b/graph.h index dcb3937..5c6e147 100644 --- a/graph.h +++ b/graph.h @@ -68,19 +68,6 @@ private: std::vector m_vertices; }; -// non-member functions - - -// template typename std::vector subtee_breathFirst(const Graph& graph, const T& root); -// template bool connected(const Graph& graph); -// template bool circular(const Graph& graph); -// template typename std::vector path(const Graph& graph, const T& a, const T& b); - - - - -// definitions - // Edge @@ -191,11 +178,9 @@ size_t Graph::numberOfVertices() const template size_t Graph::numberOfEdges() const { - size_t retval = 0; - std::accumulate(m_vertices.begin(), m_vertices.end(), retval, - [](size_t sum, const Vertex& v) + return std::accumulate(m_vertices.begin(), m_vertices.end(), 0, + [](int sum, const Vertex& v) { return sum + v.m_edges.size(); }); - return retval; } template @@ -304,13 +289,6 @@ std::vector Graph::edgesBetween(const T& source, const T& destination) c } -template -std::string Graph::serialize() const -{ - /// @todo implement me - return std::string(""); -} - template typename std::vector::Vertex >::const_iterator Graph::find(const T& data) const { @@ -328,61 +306,4 @@ typename std::vector::Vertex >::iterator Graph::find(const } -/* -template -typename std::vector subtee_breathFirst(const Graph& graph, const T& root) -{ - std::vector retval; - std::vector q; - - q.push_back(root); - while (!q.empty()) { - T node = q.front(); - q.pop_front(); - retval.push_back(node); - - const std::vector neighbours = graph.neighbours(node); - typename std::vector::const_iterator it; - for (it = neighbours.begin(); it != neighbours.end(); ++it) - q.push_back(*it); - } - return retval; -} - -template -bool connected(const Graph& graph) -{ - std::vector connected; - const std::vector vertices = graph.vertices(); - - typename std::vector::const_iterator it; - for (it = vertices.begin(); it != vertices.end(); ++it) { - const std::vector neighbours = graph.neighbours(*it); - typename std::vector::const_iterator it2; - for (it2 = neighbours.begin(); it2 != neighbours.end(); ++it2) - connected.push_back(*it2); - } - - typename std::vector::const_iterator last = std::unique(connected.begin(), connected.end()); - return graph.size == std::distance(connected.begin(), last); -} - -template -bool circular(const Graph& graph) -{ - /// @todo implemente me - return true; -} - - -template -typename std::vector path(const Graph& graph, const T& a, const T& b) -{ - // Dijkstra's algorithm for single-source shortest path - - /// @todo implemente me - return 0; -} -*/ - #endif // GRAPH_H diff --git a/main.cpp b/main.cpp index f780036..f806de4 100644 --- a/main.cpp +++ b/main.cpp @@ -29,6 +29,7 @@ int main() assert(g.numberOfEdges() == 0); assert(g.addEdge(a, b) == true); + assert(g.numberOfEdges() == 1); assert(g.edgesBetween(2, 5).size() == 1);