| 118 | // 返回值:从i号节点出发,直到把空间编号为j的节点插入,底层总共有多少数字比key[j]小 |
| 119 | // 返回值很重要,因为上游需要这个信息来改动指针的长度信息 |
| 120 | public static int addNode(int i, int h, int j) { |
| 121 | int rightCnt = 0; |
| 122 | while (next[i][h] != 0 && key[next[i][h]] < key[j]) { |
| 123 | rightCnt += len[i][h]; |
| 124 | i = next[i][h]; |
| 125 | } |
| 126 | if (h == 1) { |
| 127 | next[j][h] = next[i][h]; |
| 128 | next[i][h] = j; |
| 129 | len[j][h] = count[next[j][h]]; |
| 130 | len[i][h] = count[next[i][h]]; |
| 131 | return rightCnt; |
| 132 | } else { |
| 133 | int downCnt = addNode(i, h - 1, j); |
| 134 | if (h > level[j]) { |
| 135 | len[i][h]++; |
| 136 | } else { |
| 137 | next[j][h] = next[i][h]; |
| 138 | next[i][h] = j; |
| 139 | len[j][h] = len[i][h] + 1 - downCnt - count[j]; |
| 140 | len[i][h] = downCnt + count[j]; |
| 141 | } |
| 142 | return rightCnt + downCnt; |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | // 删除x,如果有多个,只删掉一个 |
| 147 | public static void remove(int num) { |