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

Method near2

src/class129/Code04_FindNear.java:64–87  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

62
63 // 数组手搓双向链表的实现
64 public static void near2() {
65 for (int i = 1; i <= n; i++) {
66 rank[i][0] = i;
67 rank[i][1] = arr[i];
68 }
69 Arrays.sort(rank, 1, n + 1, (a, b) -> a[1] - b[1]);
70 rank[0][0] = 0;
71 rank[n + 1][0] = 0;
72 for (int i = 1; i <= n; i++) {
73 last[rank[i][0]] = rank[i - 1][0];
74 next[rank[i][0]] = rank[i + 1][0];
75 }
76 for (int i = 1; i <= n; i++) {
77 to1[i] = 0;
78 dist1[i] = 0;
79 to2[i] = 0;
80 dist2[i] = 0;
81 update(i, last[i]);
82 update(i, last[last[i]]);
83 update(i, next[i]);
84 update(i, next[next[i]]);
85 delete(i);
86 }
87 }
88
89 // i位置右侧的j位置
90 // 看看能不能更新i右侧的最近或者次近

Callers 1

checkMethod · 0.95

Calls 3

updateMethod · 0.95
deleteMethod · 0.95
sortMethod · 0.45

Tested by

no test coverage detected