As ppl pointed out, node.parent is still point to node, not the tmp we need to make node.parent to point tmp but without parent pointer in Node class, it's hard (need to find node.parent starting from root) let's say we use parent pointer too in the Node class, then the leftRotate method can be like this, hopefully public Node leftRotate(Node node) Node tmp = node.right; if tmp == null // 어쩌다 오른쪽 자식이 없는데 회전을 시도하게되는 경우를 다뤄줍니다 ---return node; node.right = tmp.left; if node.right != null // tmp에게서 null이 아닌 노드를 물려받음, 그 노드의 부모를 변경해줘야 함 ---node.right.parent = node; tmp.left = node; tmp.parent = node.parent; // tmp의 부모를 node의 부모로 변경합니다. null이어도 괜찮습니다 if node.parent != null // node.parent가 null이면 tmp가 root가 되므로 스킵해야합니다 ---if node.parent.left == node // node가 부모의 왼쪽 자식인지 확인, 주소 비교로 가능 ------node.parent.left = tmp; // node.parent가 기존의 node 대신 tmp를 가리킴 ---else ------node.parent.right = tmp; else // node.parent 가 null 이므로 root 입니다, root를 업데이트 해줍니다 ---root = tmp; node.parent = tmp; // 이제 node.parent를 tmp로 업데이트 해줘도 순서상 문제가 없습니다 return tmp; comment i wrote is in korean, sorry too lazy to translate hopefully this is correct and helpful to others watching this amazing course
Set grandparents left child to temp right child..inst it set grandparent to temp right child..? I mean grandparebts left child is already having a right child which is null
grandParent.parent == null means root so no problem. grandParent.parent != null means we can do: grandParent.parent.left or grandparent.parent.right = rotate(grandParent)
Absolutely magnificent! Very well taught. Thank you so much!
Great content! You make this stuff much easier to understand.
There is a problem. In the code, parents of the nodes that are re-arranged or rotated are not updated.
Many many thanks! You are an awesome professor!
Great videos, thank you very much.
As ppl pointed out, node.parent is still point to node, not the tmp
we need to make node.parent to point tmp
but without parent pointer in Node class, it's hard (need to find node.parent starting from root)
let's say we use parent pointer too in the Node class, then the leftRotate method can be like this, hopefully
public Node leftRotate(Node node)
Node tmp = node.right;
if tmp == null // 어쩌다 오른쪽 자식이 없는데 회전을 시도하게되는 경우를 다뤄줍니다
---return node;
node.right = tmp.left;
if node.right != null // tmp에게서 null이 아닌 노드를 물려받음, 그 노드의 부모를 변경해줘야 함
---node.right.parent = node;
tmp.left = node;
tmp.parent = node.parent; // tmp의 부모를 node의 부모로 변경합니다. null이어도 괜찮습니다
if node.parent != null // node.parent가 null이면 tmp가 root가 되므로 스킵해야합니다
---if node.parent.left == node // node가 부모의 왼쪽 자식인지 확인, 주소 비교로 가능
------node.parent.left = tmp; // node.parent가 기존의 node 대신 tmp를 가리킴
---else
------node.parent.right = tmp;
else // node.parent 가 null 이므로 root 입니다, root를 업데이트 해줍니다
---root = tmp;
node.parent = tmp; // 이제 node.parent를 tmp로 업데이트 해줘도 순서상 문제가 없습니다
return tmp;
comment i wrote is in korean, sorry too lazy to translate
hopefully this is correct and helpful to others watching this amazing course
Amazing, super helpful
Thank you very much.
Great vedio
ty
Set grandparents left child to temp right child..inst it set grandparent to temp right child..? I mean grandparebts left child is already having a right child which is null
What if grant parent is not root and we dont have parent pointer, how do we point grand parent's parent to the new head?( in this case temp )
just for left rotation and right rotation
I think if temp.parent is None (py) then root = return variable.
grandParent.parent == null means root so no problem. grandParent.parent != null means we can do: grandParent.parent.left or grandparent.parent.right = rotate(grandParent)
Perfect +