(int i, int j)
| 90 | // 看看能不能更新i右侧的最近或者次近 |
| 91 | // 如果j==0则不更新 |
| 92 | public static void update(int i, int j) { |
| 93 | if (j == 0) { |
| 94 | return; |
| 95 | } |
| 96 | int dist = Math.abs(arr[i] - arr[j]); |
| 97 | if (to1[i] == 0 || dist < dist1[i] || (dist == dist1[i] && arr[j] < arr[to1[i]])) { |
| 98 | to2[i] = to1[i]; |
| 99 | dist2[i] = dist1[i]; |
| 100 | to1[i] = j; |
| 101 | dist1[i] = dist; |
| 102 | } else if (to2[i] == 0 || dist < dist2[i] || (dist == dist2[i] && arr[j] < arr[to2[i]])) { |
| 103 | to2[i] = j; |
| 104 | dist2[i] = dist; |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | // 双向链表中删掉i位置 |
| 109 | public static void delete(int i) { |