带有解释二叉树旋转的代码(向左或向右) [英] Code with explanation for binary tree rotation (left OR right)

查看:86
本文介绍了带有解释二叉树旋转的代码(向左或向右)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力思考如何编写用于旋转二叉树的代码.我看了 http://en.wikipedia.org/wiki/Tree_rotation 和enfuzzled.com 我一直盯着这个看了2个小时,并且更早地看了多次.我仍然在Wikipedia文章中看到问题,并且无法完全理解其他文章,例如

I have been trying to wrap my brain around how to write code for rotation of binary tree. I looked at http://en.wikipedia.org/wiki/Tree_rotation and enfuzzled.com I have been staring at this for 2 hours and have looked at it multiple times earlier. I still see problems in the wikipedia article and cannot understand the other one completely e.g.

Wikipedia文章中提到的这两行不可能一次全部成立

Both these lines mentioned in the wikipedia article cannot be true at once

让P成为Q的左孩子. 将P设置为新的根.

Let P be Q's left child. Set P to be the new root.

任何人都可以帮忙吗?谢谢

Can anyone please help?Thanks

推荐答案

根据对问题的评论,您正在寻找旋转算法的指导.这是一本出色的书中的左旋转算法 http://www .amazon.com/Introduction-Algorithms-Third-Thomas-Cormen/dp/0262033844 .

According to your comments to the question you are looking for the guidance for the rotation algorithm. Here is LEFT-ROTATE algorithm from an excellent book http://www.amazon.com/Introduction-Algorithms-Third-Thomas-Cormen/dp/0262033844.

这篇关于带有解释二叉树旋转的代码(向左或向右)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆