※ 좌측 회전
- 레드 블랙 트리에서는 좌측 회전을 하는 코드가 다음 예시와 같지만 parent 노드를 가리키는 포인터와 isLeftChild 변수를 추가로 사용해야 하기 때문에 이러한 부분들을 고려해야 한다
public void leftRotate (Node<K,V> node){
Node<K,V> temp = node.right;
node.right = temp.left;
if(node.right != null) {
node.right.parent = null;
node.right.isLeftChild = false;
}
if(node.parent == null) {
root = temp;
temp.parent = null;
}
else {
temp.parent = node.parent;
if(node.isLeftChild) {
temp.isLeftChild = true;
temp.parent.left = temp;
} else {
temp.isLeftChild = false;
temp.parent.right = temp;
}
temp.left = node;
node.isLeftChild = true;
node.parent = temp;
}
}
'기타 > What I Learned' 카테고리의 다른 글
[Database] 데이터베이스 네이밍 규칙 (0) | 2023.06.21 |
---|---|
[TIL] 자료구조 - 좌측/우측 회전 (0) | 2022.08.05 |
[TIL] 자료구조 - Rotate 메소드 (0) | 2022.08.03 |
[TIL] 자료구조 - 색상 확인 메소드 (0) | 2022.08.02 |
[TIL] 자료구조 - add 메소드 (0) | 2022.08.01 |