+ Reply to Thread
Results 1 to 5 of 5

Thread: Binary Trees in C

  1. #1
    Newbie Salrandin is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    10

    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. #2
    Guru G_Morgan is a jewel in the rough G_Morgan is a jewel in the rough G_Morgan is a jewel in the rough
    Join Date
    Oct 2007
    Age
    25
    Posts
    537
    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.

  3. #3
    Super Moderator WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther's Avatar
    Join Date
    Jul 2006
    Age
    36
    Posts
    11,689
    Blog Entries
    57
    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.
    CodeCall Blog | CodeCall Wiki | Shareware
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  4. #4
    Guru G_Morgan is a jewel in the rough G_Morgan is a jewel in the rough G_Morgan is a jewel in the rough
    Join Date
    Oct 2007
    Age
    25
    Posts
    537
    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?

  5. #5
    Newbie jbakid is an unknown quantity at this point
    Join Date
    Dec 2007
    Posts
    6

    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 04:30 PM. Reason: format

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

     

Similar Threads

  1. Binary to list??
    By TAboy24 in forum C and C++
    Replies: 3
    Last Post: 05-03-2007, 08:40 AM
  2. Writing to binary file
    By paul. in forum Pascal/Delphi
    Replies: 4
    Last Post: 04-13-2007, 08:23 PM
  3. Binary, Decimal, Hex, the Manual way!!
    By TcM in forum Tutorials
    Replies: 22
    Last Post: 01-10-2007, 12:06 AM
  4. Determine if a file is binary
    By Nightracer in forum C# Programming
    Replies: 5
    Last Post: 09-16-2006, 02:26 PM
  5. Binary Conversion in VB
    By roger in forum Visual Basic Programming
    Replies: 0
    Last Post: 06-01-2006, 10:50 AM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

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