I have a graph implemented using a struct Node
and a struct Edge
where:
- Each
Edge
has a start and an endNode
- Each
Node
maintains a list ofEdge
objects which start from or end at it
The following is one possible implementation:
struct Node;
struct Edge {
Node *st;
Node *en;
int some_data;
};
const int MAX_EDGES = 100;
struct Node {
Edge *edges[MAX_EDGES];
int some_data;
};
While the above structs can represent the graph I have in mind, I would like to do it the "Modern C++" way while satisfying the following requirements:
- Avoid pointers
- Use an
std::vector
forNode::edges
- Be able to store
Node
andEdge
objects in standard C++ containers
How is this done in Modern C++? Can all of 1-3 be achieved?
std::list
instead ofstd::vector
.std::list
andstd::vector
work out the same for me.