Create multiple tree after calling self defined struct variable

S

SAUHING LEE

I am getting some troubles for creating multiple tree after calling
self defined struct variable.

the struct is the following:

typedef struct tree {
struct tr_n_t *left;
struct tr_n_t *right;
int weight;
int key;
} node;



tree_node_t *tree;
tree = create_tree();

I call tree = create_tree(); when create a new tree.
Let say i want want to create a new struct call "multiple_tree" and
then create multiple trees according to its parameter. For example:
multiple_tree *mt;
mt= create_tree(5)
The function creates 5 trees and assigns all 5 trees to variable mt.
Question: How can i store arbitrary amount of tree in a variable?
How can i access the tree stored in the variable?
 
G

Guest

I am getting some troubles for creating multiple tree after calling
self defined struct variable.

the term is "recursive"
the struct is the following:

typedef struct tree {
                    struct tr_n_t  *left;
                    struct tr_n_t *right;
                    int           weight;
                     int        key;
                      } node;

tree_node_t *tree;
 tree = create_tree();

we don't know what many of your types are
I call  tree = create_tree(); when create a new tree.
Let say i want want to create  a new struct call "multiple_tree" and
then create multiple trees according to its parameter. For example:
 multiple_tree *mt;
mt= create_tree(5)
The function creates 5 trees and assigns all 5 trees to variable mt.
Question: How can i store arbitrary amount of tree in a variable?

you can't
How can i access the tree stored in the variable?

mt needs to be able to hold multiple values. It could be an array
for instance

tree mt[5];

but you can't assign arrays (thet aren't "first class objects").
You could make mt some sort of struct
You could define a new function.

void create_multi_tree (tree mt[], tree_count);

If you want your multi-tree holder to be a bit cleverer
you could make it a linked list. Or even a tree...

You probably need to explain more about why you are doing
this
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top