Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

AVL-Tree Balancefactor

Name: cyan 2008-07-10 14:49

ok, to calculate the balancefactor of a binary tree you have to subtract the height of the right subtree from the left subtree...

normally you do something like this:
//tree structure

struct node{
   int val;
   struct node * left, * right;
};

struct node * root = NULL;

//Inserting some numbers
void insert(int a[]){
blablabla;
}

//function returning the height of the tree with root p)
int height(struct node *p){
blablabla;
}

int balancefactor(struct node *p){
   if(!p) return 0;
   return height(p->right)-height(p->left);
}

now check this out:
i have to write a recursive function "balancefactor2" that calculates the balancefactor without calling another function.
How to do it /prog/?

Name: Anonymous 2008-07-10 16:24

>>3
Surely you mean [m] tags... [code] tags have eye-burning built in.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List