//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:
Anonymous2008-07-10 14:54
int SICP(){
read;
}
Name:
Anonymous2008-07-10 14:56
I suggest doing bad things to everyone who doesn't use code tags. Ever though I want to help you, I can't, because my eyes are burning :(
//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);
}
Fuck code tags
Name:
Anonymous2008-07-10 16:24
>>3
Surely you mean [m] tags... [code] tags have eye-burning built in.
Name:
Anonymous2008-07-10 16:39
Listen up, dipshit. You don't ``calculate'' the balance factor of a node in an AVL tree, you keep track of it while inserting and deleting so you can just look it up.
heyho, mr. smartguy. I'm aware that there are better solutions then calculating it with a rec function.
But that's from a CS test and therefore i don't really have an option here, do i?
Create your own stack? You could probably even get away with using an array for a stack since the tree is balanced. An array of n node pointers can deal with a tree of size up to 2n + 1 - 1 or something.
All work and no play makes Jack a dull boy
Allɳᱼ work and no play makesȥ䯼 Jack a dull敝以 boy
All⍭ᡁ work and no play makes貍泊 Jack a dull㨟窡 boy
All㔤 work and no play makesⰖ湊 Jack a dull㩽갡 boy
All縹ᖝ work and no play makes븆㰽 Jack a dull醴䩾 boy
All이 work and no play makes Jack a dull훂붌 boy
Allӭ work and no play makes輜鼵 Jack a dull뺛栄 boy