From a99ae6007f8f82fe049913d52611d5149ebcf7df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=93=E8=88=AA?= <1210603696@qq.com> Date: Mon, 9 Feb 2015 14:18:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90adjacent=5Fnodes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TinySTL/Detail/Graph.impl.h | 17 ++++++++++++++++- TinySTL/Graph.h | 7 ++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/TinySTL/Detail/Graph.impl.h b/TinySTL/Detail/Graph.impl.h index 146015a..a3118d9 100644 --- a/TinySTL/Detail/Graph.impl.h +++ b/TinySTL/Detail/Graph.impl.h @@ -42,12 +42,27 @@ namespace TinySTL{ if (equal_func(pair.first.first, index)) return bucket_iterator(this, (pair.second).end()); } - throw std::exception("return end error"); + //throw std::exception("return end error"); + return bucket_iterator(); } template size_t graph::size()const{ return size_; } + template + typename graph::node_sets + graph::adjacent_nodes(const Index& index){ + node_sets s; + for (auto it = begin(index); it != end(index); ++it){ + s.push_back(*it); + } + return s; + } + template + typename graph::node_sets + graph::adjacent_nodes(const node& n){ + return adjacent_nodes(n.first); + } //******************************************************************************** template graph_iterator& graph_iterator::operator ++(){ diff --git a/TinySTL/Graph.h b/TinySTL/Graph.h index 84bdb3a..460aad2 100644 --- a/TinySTL/Graph.h +++ b/TinySTL/Graph.h @@ -30,14 +30,15 @@ namespace TinySTL{ virtual ~graph(){}; virtual void add_node(const node& item, const node_sets& nodes) = 0; //virtual void delte_node(const node& item) = 0; - //virtual node_sets adjacent_nodes(const node& n) = 0; - //virtual node_sets adjacent_nodes(const Index& index) = 0; //virtual void DFS(visiter_func_type func) = 0; //virtual void BFS(visiter_func_type func) = 0; static node& new_node(const Index& index, const Value& val); bool is_contained(const Index& index); inline static node_sets empty_node_set(); + node_sets adjacent_nodes(const Index& index); + node_sets adjacent_nodes(const node& n); + inline bool empty()const; inline size_t size()const; inline bucket_iterator begin(const Index& index); @@ -56,7 +57,7 @@ namespace TinySTL{ typedef graph graph_type; typedef typename list::iterator inner_it_type; public: - graph_iterator(cntrPtr c, inner_it_type iit) + explicit graph_iterator(cntrPtr c = nullptr, inner_it_type iit = inner_it_type()) :container_(c), inner_it_(iit){} graph_iterator& operator ++(); const graph_iterator operator ++(int);