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

Method sort

src/class028/Code01_RadixSort.java:52–72  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

50 }
51
52 public static void sort() {
53 // 如果会溢出,那么要改用long类型数组来排序
54 // 找到数组中的最小值
55 int min = arr[0];
56 for (int i = 1; i < n; i++) {
57 min = Math.min(min, arr[i]);
58 }
59 int max = 0;
60 for (int i = 0; i < n; i++) {
61 // 数组中的每个数字,减去数组中的最小值,就把arr转成了非负数组
62 arr[i] -= min;
63 // 记录数组中的最大值
64 max = Math.max(max, arr[i]);
65 }
66 // 根据最大值在BASE进制下的位数,决定基数排序做多少轮
67 radixSort(bits(max));
68 // 数组中所有数都减去了最小值,所以最后不要忘了还原
69 for (int i = 0; i < n; i++) {
70 arr[i] += min;
71 }
72 }
73
74 // 返回number在BASE进制下有几位
75 public static int bits(int number) {

Callers 15

mainMethod · 0.95
computeMethod · 0.45
mainMethod · 0.45
mainMethod · 0.45
minimumEffortMethod · 0.45
atLeast2Method · 0.45
minAverageSum2Method · 0.45
maxEventsMethod · 0.45
eraseOverlapIntervalsMethod · 0.45
maxMeeting2Method · 0.45
numRabbitsMethod · 0.45
makeSimilarMethod · 0.45

Calls 3

radixSortMethod · 0.95
bitsMethod · 0.95
maxMethod · 0.45

Tested by

no test coverage detected