class Graph{
friend istream& operator>>(istream& in, Graph& A);
friend istream& operator>>(istream& in, Graph* A);
friend ostream& operator<<(ostream& out,const Graph& A);
friend ostream& operator<<(ostream& out,const Graph* A);
private:
GnodePtrBag d_nodes;
GedgePtrBag d_edges;
Graph(const Graph&);
Graph& operator=(const Graph&);
public:
Graph();
~Graph();
Gnode *addNode(const char *nodeName);
Gnode *findNode(const char *nodeName);
void removeNode(Gnode *node);
Gedge *addEdge(Gnode *from,Gnode *to,double weight);
Gedge *findEdge(Gnode *from,Gnode *to);
void removeEdge(Gedge *edge);
const GnodePtrBag& nodes() const;
const GedgePtrBag& edges() const;
istream& grab(istream& in);
ostream& print(ostream& out) const;
};
#endif
The graph class actually consists of a bag of node pointers and a bag of edge pointers for each node. Then, of course, there is the capability to add, find, and remove nodes. Such functions then imply the ability to add, find, and remove edges between nodes. While the actual pointer bags are private, there are public interfaces so that the information can be accessed.