Create multiple tree after calling self defined struct variable

Discussion in 'C Programming' started by SAUHING LEE, Dec 5, 2008.

  1. SAUHING LEE

    SAUHING LEE Guest

    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?
    SAUHING LEE, Dec 5, 2008
    #1
    1. Advertising

  2. SAUHING LEE

    Guest

    On 5 Dec, 05:08, SAUHING LEE <> 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
    , Dec 5, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ralf W. Grosse-Kunstleve
    Replies:
    16
    Views:
    559
    Lonnie Princehouse
    Jul 11, 2005
  2. Ralf W. Grosse-Kunstleve
    Replies:
    18
    Views:
    578
    Bengt Richter
    Jul 11, 2005
  3. Ralf W. Grosse-Kunstleve
    Replies:
    2
    Views:
    387
    Dan Sommers
    Jul 12, 2005
  4. falcon
    Replies:
    0
    Views:
    357
    falcon
    Jul 31, 2005
  5. Bart Kastermans
    Replies:
    6
    Views:
    383
    Bart Kastermans
    Jul 13, 2008
Loading...

Share This Page