File tree 2 files changed +20
-1
lines changed
yoonexample/src/main/java/search/binarysearchtree
2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -71,4 +71,23 @@ private BinaryTreeNode<E> rotateRL(BinaryTreeNode<E> binaryTreeNode) {
71
71
parentNode .changeRightSubTree (rotateLL (childNode )); // 부분적 LL회전
72
72
return rotateRR (parentNode ); // RR회전
73
73
}
74
+
75
+ private void rebalance () {
76
+ int equilibriumFactor = getEquilibriumFactor (super .node );
77
+
78
+ if (equilibriumFactor > 1 ) { // LL OR LR
79
+ if (getEquilibriumFactor (super .node .getLeftSubTree ()) > 0 ) {
80
+ super .node = rotateLL (super .node );
81
+ } else {
82
+ super .node = rotateLR (super .node );
83
+ }
84
+ }
85
+ if (equilibriumFactor < -1 ) { // RR OR RL
86
+ if (getEquilibriumFactor (super .node .getRightSubTree ()) < 0 ) {
87
+ super .node = rotateRR (super .node );
88
+ } else {
89
+ super .node = rotateRL (super .node );
90
+ }
91
+ }
92
+ }
74
93
}
Original file line number Diff line number Diff line change 7
7
public class LinkedBinarySearchTreeNode <E > implements BinarySearchTreeNode <E > {
8
8
9
9
private final Comparator <E > comparator ;
10
- private BinaryTreeNode <E > node ;
10
+ protected BinaryTreeNode <E > node ;
11
11
12
12
public LinkedBinarySearchTreeNode (E data , Comparator <E > comparator ) {
13
13
this .node = new LinkedBinaryTreeNode <>(data );
You can’t perform that action at this time.
0 commit comments