Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   Create multiple tree after calling self defined struct variable (http://www.velocityreviews.com/forums/t647318-create-multiple-tree-after-calling-self-defined-struct-variable.html)

SAUHING LEE 12-05-2008 05:08 AM

Create multiple tree after calling self defined struct variable
 
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?

nick_keighley_nospam@hotmail.com 12-05-2008 09:58 AM

Re: Create multiple tree after calling self defined struct variable
 
On 5 Dec, 05:08, SAUHING LEE <saturn...@yahoo.com> wrote:


> 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


--
Nick Keighley



All times are GMT. The time now is 01:21 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.