Thread: Structures, pointers and AVL trees

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    1

    Unhappy Structures, pointers and AVL trees

    HI

    I've a structure which consists of two char parts and a pointer.
    struct ex_data
    {
    char part1[13];
    char part2[2];
    } exdata, *exdata_prt;

    The pointer is then being passed into an avl tree. I've written a function to "surf" the tree printing out details of the two parts. But I cannot get it to work, I need accessing the avl tree and return the contents of the of the structure. Can anyone help with this problem?

    Many thanks.
    Mark Shatford.

  2. #2
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    In your structure, you need to have pointers to the childs.

    Code:
    typedef struct ex_data exdata;
    typedef struct ex_data *exdata_ptr;
    
    struct ex_data
    {
        char part1 [13];
        char part2 [2];
        exdata_ptr left_child;
        exdata_ptr right_child;
    };
    Traversing can be done as follows:

    Code:
    /* assume tree_ptr points at some node */
    
    /* now let tree_ptr point to a child */
    if (next_child == LEFT_CHILD)
    {
        tree_ptr = tree_ptr->left_child;
    }
    else
    {
        tree_ptr = tree_ptr->right_child;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with AVL Tree Pointers
    By Bnchs in forum C Programming
    Replies: 4
    Last Post: 04-06-2008, 06:09 AM
  2. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM