Code explaining rotation of a binary tree (left or right)

I am trying to wrap my brain around how to write code to rotate a binary tree. I looked at http://en.wikipedia.org/wiki/Tree_rotation and enfuzzled.com I looked at this for 2 hours and looked at it several times earlier. I still see problems in the wikipedia article and cannot fully understand the other, for example.

Both of these lines mentioned in the wikipedia article cannot be true right away.

Let P be Q left child. Set P as the new root.

Can anybody help? thanks

+4
source share
3 answers

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

alt text

+5
source

"Let P be the Q-left child. Set P as the new root." Basically, a description of rotation to the right or clockwise:

QP / => \ PQ 
+1
source

Here is LEFT-ROTATE in my edition of Corman's book

LEFT-ROTATE algorithm for BST

0
source

Source: https://habr.com/ru/post/1334257/


All Articles