next up previous contents
Next: Iterators Up: The Graph Class: Previous: The Class Description: Header:

The Constructor and Destructor

Graph::Graph(){}
Graph::~Graph()
{
  for(GedgePtrBagIter eit(d_edges); eit; ++eit){
    if(eit()!=NULL)
      delete eit();
    }
  for(GnodePtrBagIter nit(d_nodes); nit; ++nit){
    delete nit();
    }
}

The constructor does nothing. The graph is basically defined by the nodes which reside in it. The destructor steps through all of the edges via the GedgePtrBagIter iterator and deletes each edge until there are none remaining. The is the edge pointer bag for the graph itself. So it contains all edges associated with any node included in the graph. (Note there is an edge pointer bag associated with each node of the graph as well.) Then, the nodes are traversed via the GnodePtrBagIter iterator and each node is deleted.


Jim Peterson
1999-05-17