(int i)
| 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); |
no test coverage detected