- #1
evinda
Gold Member
MHB
- 3,836
- 0
Hello! (Wave)
I had a test today , it was given an AVL-tree and I had to find the height of the node with key $k$.
That's what I have tried:
Could you tell me if it is right? (Thinking)
I had a test today , it was given an AVL-tree and I had to find the height of the node with key $k$.
That's what I have tried:
Code:
Height(T,K){
if (T==NULL) return;
pointer R;
R=LookUp(T,K);
int k=height(R);
return k;
} height(pointer R){
static j=0,l=0;
if (R==NULL) return 0;
if (R->lc!=NULL) l=1+height(R->lc);
if (R->rc!=NULL) j=l-height(R->lc)+height(R->rc);
if (R->rc==NULL and R->lc==NULL) return 1;
return max(l,j);
}