template Graph::Graph(bool directional) :_directional(directional){}; template void Graph::add_vertex(const V& name){ if(!has_vertex(name)){ _short_names.insert({name, _edges.size()}); _long_names.push_back(name); _edges.emplace_back(); } } template void Graph::add_edge(const V& name1, const V& name2, double lenght){ add_vertex(name1); add_vertex(name2); _add_edge(name1, name2, lenght); if(!_directional) _add_edge(name2, name1, lenght); } template bool Graph::has_vertex(const V& name) const{ return _short_names.find(name) != _short_names.end(); } template bool Graph::has_edge(const V& name1, const V& name2) const{ if(!has_vertex(name1) || !has_vertex(name2)) return false; auto s_name1 = (*_short_names.find(name1)).second; auto s_name2 = (*_short_names.find(name2)).second; for(const auto& item:_edges[s_name1]){ if(item.first == s_name2) return true; } return false; } template void Graph::print() const{ int i = 0; for(auto it = _edges.begin(); it != _edges.end(); ++it, ++i){ std::cout<<_long_names[i]<<" -> "; for(const auto &item:*it){ std::cout<<"("<<_long_names[item.first]<<" , "< void Graph::_add_edge(const V& name1, const V& name2, double lenght){ _edges[_short_names[name1]].push_back({_short_names[name2], lenght}); }