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

Method update

src/class129/Code04_FindNear.java:92–106  ·  view source on GitHub ↗
(int i, int j)

Source from the content-addressed store, hash-verified

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) {

Callers 2

near1Method · 0.95
near2Method · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected