As novice, I m trying to generate a DAG with C (or C++).
struct Node
{
Link *incomingEdge, *outgoingEdge;
};
struct Link
{
Node *origin, *destination;
};
simply in my code there are only one incoming and outgoing edges for each node. However, a node could have several incident edges. Moreover, number of incident edges might change for each node.
how can I generate different number of pointers for each node ?
assume that I have;
nodeA with 5 incoming edges and 4 outgoing edges. nodeB with 3 incoming edges and 6 outgoing edges.
so number of pointers are changing for each node.
考虑使用指针向量
std::vector<Link *> incomingEdge;
It depends what you need. The graph is completely desccribed by the edges, so the easy answer is, omit *incomingEdge, *outgoingEdge
from the node definition. But a linked list or an appropriate container from std::
of adjecent nodes will be probably be better for the algorithms you are going to implement.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.