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

Method sort

src/class185/Code05_OpenStore1.java:339–354  ·  view source on GitHub ↗
(int[] age, long[] sum, int l, int r)

Source from the content-addressed store, hash-verified

337 // 每个对象两个属性(age, sum),所有对象根据年龄排序
338 // java自带的排序慢,手撸双指针快排,C++实现时可以用自带的排序
339 public static void sort(int[] age, long[] sum, int l, int r) {
340 if (l >= r) return;
341 int i = l, j = r, pivot = age[(l + r) >> 1], tmp1;
342 long tmp2;
343 while (i <= j) {
344 while (age[i] < pivot) i++;
345 while (age[j] > pivot) j--;
346 if (i <= j) {
347 tmp1 = age[i]; age[i] = age[j]; age[j] = tmp1;
348 tmp2 = sum[i]; sum[i] = sum[j]; sum[j] = tmp2;
349 i++; j--;
350 }
351 }
352 sort(age, sum, l, j);
353 sort(age, sum, i, r);
354 }
355
356 public static long nodeCnt, pathSum;
357

Callers 1

mainMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected