MCPcopy Create free account
hub / github.com/algorithmzuo/algorithm-journey / maintain

Method maintain

src/class148/Code01_AVL1.java:81–100  ·  view source on GitHub ↗
(int i)

Source from the content-addressed store, hash-verified

79 // 如果命中了某种违规情况,就进行相应调整
80 // 返回树的头节点的空间编号
81 public static int maintain(int i) {
82 int lh = height[left[i]];
83 int rh = height[right[i]];
84 if (lh - rh > 1) {
85 if (height[left[left[i]]] >= height[right[left[i]]]) {
86 i = rightRotate(i);
87 } else {
88 left[i] = leftRotate(left[i]);
89 i = rightRotate(i);
90 }
91 } else if (rh - lh > 1) {
92 if (height[right[right[i]]] >= height[left[right[i]]]) {
93 i = leftRotate(i);
94 } else {
95 right[i] = rightRotate(right[i]);
96 i = leftRotate(i);
97 }
98 }
99 return i;
100 }
101
102 // 增加数字num,重复加入算多个词频
103 public static void add(int num) {

Callers 3

addMethod · 0.95
removeMethod · 0.95
removeMostLeftMethod · 0.95

Calls 2

rightRotateMethod · 0.95
leftRotateMethod · 0.95

Tested by

no test coverage detected