Closed Thread
Results 1 to 5 of 5

Thread: Binary Trees in C

  1. #1
    Salrandin is offline Newbie
    Join Date
    Oct 2007
    Posts
    10
    Rep Power
    0

    Binary Trees in C

    I need to know how to implement and use this,
    in order to program an order of operations calculator,
    neone know a very comprehensive online tutorial?

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Oct 2007
    Posts
    538
    Rep Power
    21
    This is more general theory. Basically a binary tree node has three variables:
    1. A left child
    2. A right child
    3. A value

    The children are pointers to binary tree nodes (i.e. the data structure is recursive). When a child is null it signifies that it is empty.

    All you need is a variety of functions for the insertion and removal of values and so on. These functions will differ depending on what order you will be storing the data in. The functions will usually be recursive themselves.

  4. #3
    Join Date
    Jul 2006
    Posts
    16,466
    Blog Entries
    74
    Rep Power
    143
    There is an extensive amount of theory that you will not need for binary trees, and some you will. In particular, traversing the tree will be important, but balancing it is probably unnecessary.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  5. #4
    Join Date
    Oct 2007
    Posts
    538
    Rep Power
    21
    Quote Originally Posted by WingedPanther View Post
    There is an extensive amount of theory that you will not need for binary trees, and some you will. In particular, traversing the tree will be important, but balancing it is probably unnecessary.
    Unless you are implementing a heap . That's why I said it's very application specific. The functions are almost entirely dependent on the domain. So the question remains what he wants a binary tree for?

  6. #5
    jbakid is offline Newbie
    Join Date
    Dec 2007
    Posts
    6
    Rep Power
    0

    Some i=useful info

    Here's to define a tree type:

    [HIGHLIGHT="C"]typedef struct _tnode{
    struct _tnode* left;
    struct _tnode* right;
    struct _tnode* parent;
    void* data;
    } tnode;[/HIGHLIGHT]

    And to initialise it:

    [HIGHLIGHT="C"]tnode* mytnode = (tnode*)malloc(sizeof(tnode));
    tnode->left = tnode->right = tnode->parent = NULL;[/HIGHLIGHT]

    And to traverse it (using a void function wit input of type void*):

    [HIGHLIGHT="C"]void traverse_tree(tnode* top, void(*func)(void*)){
    if(top->left) traverse_tree(left, func);
    func(top->data);
    if(top->right) traverse_tree(right, runc);
    }[/HIGHLIGHT]
    Last edited by jbakid; 12-02-2007 at 02:30 PM. Reason: format

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Binary trees structure comparison
    By Slammerek in forum C and C++
    Replies: 2
    Last Post: 07-14-2011, 07:55 AM
  2. Traversal of binary search trees
    By kakariki in forum General Programming
    Replies: 3
    Last Post: 07-14-2011, 07:52 AM
  3. [Help] MFC maze (Binary Trees)
    By Beeko in forum C and C++
    Replies: 12
    Last Post: 01-04-2011, 10:21 PM
  4. Balancing Binary Search Trees
    By Daskill in forum General Programming
    Replies: 6
    Last Post: 12-08-2008, 11:46 AM
  5. Need help with binary trees.
    By Daskill in forum General Programming
    Replies: 9
    Last Post: 12-08-2008, 08:13 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts