Structures, pointers and AVL trees

This is a discussion on Structures, pointers and AVL trees within the C Programming forums, part of the General Programming Boards category; HI I've a structure which consists of two char parts and a pointer. struct ex_data { char part1[13]; char part2[2]; ...

  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,386
    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, 07: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, 04:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21