Levin - 11 months ago 52

C Question

I'm trying to solve how save nodes of graph. Every node can have more ancestors and more descendants. Now I have this struct:

`struct Node`

{

int m_Value;

int m_Index; // end Node in m_Nodes

int m_Length; // actual size of m_Nodes and m_Prev (for realloc)

Node* m_Nodes; // dynamic array (descendants)

Node* m_Prev; // dynamic array (ancestors)

}

I'm not sure if this is the best way. The graph can look like this:

`1`

2 3

4

Edges: [1,2], [1,3], [2,4], [3,4], [4,1]

Thank you for your opinions.

Answer Source

You can save edge and point separately.And you need a function to get all edge of one point. so the memory malloc & free operation me be less