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?
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.
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.
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
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks