*** Question on Data Structures ***
Greeting everybody,
I do have a question with one of the data structures that I'm trying to create (template below) -
Code:
int BCount;
int Ccount;
struct A {
struct B* Bptrs[]; <- array of pointers to struct B
struct C* Cptrs[]; <- array of pointers to struct C
struct A* next; <- pointer to next A node
} *A <- pointer to struct A
struct B {
struct A* Aptr; <- pointer to struct A
struct C* Cptrs[]; <- array of pointers to struct C
struct B* next; <- pointer to next B node
} *B <- pointer to struct A
struct C {
struct A* Aptr; <- pointer to struct A
struct B* Bptr; <- pointer to struct B
struct C* next; <- pointer to next C node
} *C <- pointer to struct C
As you can see, the three structures are linked to one another. Now for the questions -
a. Can I setup all the nodes for one struct (leaving the pointers to other structs as NULL), and have them pointing to the correct instances, once nodes have been created for other structures (holds good for pointers in other structures as well).
b. I have an array of pointers to other structs in A and B. The length of the array (more like, number of pointers required), would be decided by the variables, BCount and CCount that would be available only during runtime. Can this be done? Dynamically creating storage for an array of pointers? If yes, please let me know.
Regards,
CT