I'm writing code for a graph.
Which is better for implementing a digraph with weighted edges?
set 1
class Node ;
class Edge
{
Node *src, *dst ;
int cost ;
} ;
class Node
{
list<Edge> edges ; // slightly redundant.
// because an edge connects two nodes,
// the information in each Edge's src
// is redundant to this
} ;
set 2
// Each node has a map of nodes it connects to,
// with the value being the edge weight
class Node
{
map<Node*, int> connections ; // this is map<node, cost>
} ;
Of course, any other suggestions / approaches are appreciated as well!