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

Method maintain

src/class148/FollowUp1.java:60–79  ·  view source on GitHub ↗
(int i)

Source from the content-addressed store, hash-verified

58 }
59
60 public static int maintain(int i) {
61 int lh = height[left[i]];
62 int rh = height[right[i]];
63 if (lh - rh > 1) {
64 if (height[left[left[i]]] >= height[right[left[i]]]) {
65 i = rightRotate(i);
66 } else {
67 left[i] = leftRotate(left[i]);
68 i = rightRotate(i);
69 }
70 } else if (rh - lh > 1) {
71 if (height[right[right[i]]] >= height[left[right[i]]]) {
72 i = leftRotate(i);
73 } else {
74 right[i] = rightRotate(right[i]);
75 i = leftRotate(i);
76 }
77 }
78 return i;
79 }
80
81 public static void add(int num) {
82 head = add(head, 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