グラフクラスのイテレータを実装しています
class iterator_node {
private:
Graph* gr_;
Node* curNode_;
public:
iterator_node() : gr_(NULL),curNode_(NULL) {}
iterator_node(Graph& ddg) : gr_(&ddg),curNode_(NULL) {}
~iterator_node() {}
}
また、関数Graph
を実装する必要があるクラスがありますinsert
class Graph {
private:
//....
map<NodeID,Node*> nodes_;
public:
pair<iterator_node,bool> insert(const NodeID nodeId,const NodeLabel nodeLabel);
}
pair<iterator_node,bool> Graph::insert(const NodeID nodeId,const NodeLabel nodeLabel)
{
DDG::iterator_node itNode(*this);
pair<Graph::iterator_node,bool> res(itNode,false);
Node* node = new Node(nodeId,false,nodeLabel);
pair<map<NodeID,Node*>::iterator,bool> nodeInsRet = nodes_.insert(pair<NodeID,Node*> (nodeId,node));
if (nodeInsRet.second == false) {
std::cout << "Node with nodeID=" << nodeId << " already exists \n";
delete node;
}
else {
res.second = true;
//!!Question!!!!
//should update curNode_; in res`s iterator (res.first)
//what is a relevan correct way to do it?
}
return res;
}