next up previous contents
Next: GnodePtrBagManip Constructor: Up: The Graph Class: Previous: GnodePtrBagIter Constructor:

Remove a Node:

This agent removes a node from a given graph. It is one of the functions which uses the manipulator class. The remove agent is as follows.

void Graph::removeNode(Gnode *node)
{
  GnodePtrBagManip nodeMan(&d_nodes);
  while(nodeMan){
    if(nodeMan()==node){
      for(GedgePtrBagIter it(nodeMan()->edges());it;++it){
        d_edges.removeAll(it());
        }
      nodeMan.remove();
      }
    else{
      nodeMan.advance(); 
      }        
    } 
}

Hence, in outline, the remove node process is thus:

void Graph::removeNode(Gnode *node)
{
  GnodePtrBagManip nodeMan(&d_nodes);   //construct the node bag manipulator
  while(nodeMan){                       //manually step through the nodes in the bag
    if(nodeMan()==node){                //if we match the desired node
      //remove all edges associated with this node
        }
      nodeMan.remove();                 //the edges are gone, so remove node
                                        //the remove method also moves to the next node
                                        //in the bag               
      }
    else{                               //this is not the desired node so just advance
      nodeMan.advance();                
      }        
    } 
}

We need to discuss these methods in detail. The manipulator constructor is called to construct the nodeMan manipulator.



 

Jim Peterson
1999-05-17