diff --git a/TinySTL/Detail/Graph.impl.h b/TinySTL/Detail/Graph.impl.h index 146015a3501f8fd9f281a11942b0fefc8823cf4f..a3118d92da83610dedc4eaa281ffef5fce109378 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 84bdb3a1aa28160d2ff424dd13f14fcd784328df..460aad2302c4108a1fe196a1b14cc0219c4ef689 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);