-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The height of the node in AVL tree is wrong #1
Comments
hey, i am not sure what are you trying to say. can you please elaborate? |
The first input data 10 is the root, then the sencond data 4 is the left substree of 10. After the third data 6 is inserted in the AVL tree. The balance factor of the root is 2>1, so, the tree is unbalanced. This is a right of left unbalanced tree, so, after the rebalance processing, the three nodes' balance factors should all be ZERO. However, I run your code, the result is that the balance factors are not all zero. |
So i inserted (10, 4, 6) in that order. After rebalancing(left right case) i did the above preorder traversal. And this was the output. this looks good to me. Can you share the changes you made in the code?
|
Do we use the same code? I only modify the "outpreorder" function so that I
can print the balance factor. The attachment is your code with my
modification. You can run it.
Amit Bansal <[email protected]> 于2018年11月29日周四 上午12:49写道:
… `void preorder(struct Node* root)
{
if(root==NULL)
return;
printf("Data : %d | Balancing factor : %d\n",root->data, Balance(root));
preorder(root->left);
preorder(root->right);
}
So i inserted (10, 4, 6) in that order. After rebalancing(left right case)
i did the above preorder traversal. And this was the output. this looks
good to me. Can you share the changes you made in the code.
Preorder traversal of tree is :
Data : 6 | Balancing factor : 0
Data : 4 | Balancing factor : 0
Data : 10 | Balancing factor : 0
`
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#1 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AfSuZbc-1jUX9uJ4_FtEnVnXup2tFl_Yks5uz5-ngaJpZM4Yv-Hr>
.
--
*"PZY make life better ! "*
|
There is no attachment here. |
I input the data 10, 4, 6. After the rebalance, the height of each of the three nodes should be ZERO. However, in your AVL tree code, the height isn't ZERO. You can check it.
The text was updated successfully, but these errors were encountered: