next up previous contents
Next: Gedge Constructor: Up: The Graph Class: Previous: GnodePtrBagLink Constructor

Add an Edge:

Now that we know how to add nodes to the graph, we need to add the edges which link the nodes. This done with the following agent.

Gedge *Graph::addEdge(Gnode* from,Gnode* to,double weight)
{
  Gedge *p = new Gedge(from,to,weight);
  d_edges.add(p);
  from->add(p);
  to->add(p);
  return p;
}

Once again, this innocent looking little function has a lot of complexity hidden underneath. It's very similar to the addition of a node in regard to the class dependencies. The first line calls the constructor for the Gedge class (which will in turn call a constructor for the Edge class). The Gedge constructor is:



 

Jim Peterson
1999-05-17