Question: You need to complete the implementation of insert _ edge, insert _ edge _ undirected, insert _ vertex, erase _ edge, erase _ vertex functions.

You need to complete the implementation of insert_edge, insert_edge_undirected, insert_vertex, erase_edge, erase_vertex functions.
#ifndef _GRAPH_H_
#define _GRAPH_H_
#include
#include
#include
#include
#include
#include
#include
// Uncomment if using unordered_set to store edges with boost hash function
//#include
////////////////////////////////////////////////////////////////////////////////
/// A generic adjacency-list graph where each vertex stores a VertexProperty and
/// each edge stores an EdgeProperty.
////////////////////////////////////////////////////////////////////////////////
template
class graph {
// The vertex and edge classes are forward-declared to allow their use in the
// public section below. Their definitions follow in the private section
// afterward.
class vertex;
class edge;
struct vertex_hash;
struct edge_hash;
struct vertex_eq;
struct edge_eq;
struct edge_comp;
public:
// Required public types
/// Unique vertex identifier
typedef size_t vertex_descriptor;
/// Unique edge identifier represents pair of vertex descriptors
typedef std::pair edge_descriptor;
///@brief A container for the vertices. It should contain "vertex*" or
/// shared_ptr.
typedef std::unordered_set MyVertexContainer;
///@brief A container for the edges. It should contain "edge*" or
/// shared_ptr.
//typedef std::unordered_set MyEdgeContainer;
typedef std::set MyEdgeContainer;
///@brief A container for the adjacency lists. It should contain
/// "edge*" or shared_ptr.
//typedef std::unordered_set MyAdjEdgeContainer;
typedef std::set MyAdjEdgeContainer;
// Vertex iterators
typedef typename MyVertexContainer::iterator vertex_iterator;
typedef typename MyVertexContainer::const_iterator const_vertex_iterator;
// Edge iterators
typedef typename MyEdgeContainer::iterator edge_iterator;
typedef typename MyEdgeContainer::const_iterator const_edge_iterator;
// Adjacency list iterators
typedef typename MyAdjEdgeContainer::iterator adj_edge_iterator;
typedef typename MyAdjEdgeContainer::const_iterator const_adj_edge_iterator;
// Required graph operations
///@brief Constructor/destructor
graph() : m_max_vd(0){}
~graph(){
clear();
}
graph(const graph&)= delete; ///< Copy is disabled.
graph& operator=(const graph&)= delete; ///< Copy is disabled.
///@brief vertex iterator operations
vertex_iterator vertices_begin(){return m_vertices.begin();}
const_vertex_iterator vertices_cbegin() const {return m_vertices.cbegin();}
vertex_iterator vertices_end(){return m_vertices.end();}
const_vertex_iterator vertices_cend() const {return m_vertices.cend();}
///@brief edge iterator operations
edge_iterator edges_begin(){return m_edges.begin();}
const_edge_iterator edges_cbegin() const {return m_edges.cbegin();}
edge_iterator edges_end(){return m_edges.end();}
const_edge_iterator edges_cend() const {return m_edges.cend();}
///@brief Define accessors
size_t num_vertices() const {return m_vertices.size();}
size_t num_edges() const {return m_edges.size();}
vertex_iterator find_vertex(vertex_descriptor vd){
vertex v(vd, VertexProperty());
return m_vertices.find(&v);
}
const_vertex_iterator find_vertex(vertex_descriptor vd) const {
vertex v(vd, VertexProperty());
return m_vertices.find(&v);
}
edge_iterator find_edge(edge_descriptor ed){
edge e(ed.first, ed.second, EdgeProperty());
return m_edges.find(&e);
}
const_edge_iterator find_edge(edge_descriptor ed) const {
edge e(ed.first, ed.second, EdgeProperty());
return m_edges.find(&e);
}
///@todo Define modifiers
vertex_descriptor insert_vertex(const VertexProperty& vp){
return m_max_vd;
}
edge_descriptor insert_edge(vertex_descriptor sd, vertex_descriptor td,
const EdgeProperty& ep){
return std::make_pair(sd, td);
}
void insert_edge_undirected(vertex_descriptor sd, vertex_descriptor td,
const EdgeProperty& ep){
}
void erase_vertex(vertex_descriptor vd){
}
void erase_edge(edge_descriptor ed){
}
////end of @todo
void clear(){
m_max_vd =0;
for(auto v : m_vertices)
delete v;
m_vertices.clear();
for(auto e : m_edges)
delete e;
m_edges.clear();
}
// Friend declarations for input/output.
template

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!