因此,我正在尝试针对基数排序实现此伪代码,并且不了解如何创建此代码隐含必须创建的2D ArrayList。我看过有关创建2D ArrayList的其他文章,但不了解如何在这种情况下正确实现它。任何帮助将不胜感激。
RadixSort(array, arraySize) {
buckets = create array of 10 buckets
// Find the max length, in number of digits
maxDigits = RadixGetMaxLength(array, arraySize)
// Start with the least significant digit
pow10 = 1
for (digitIndex = 0; digitIndex < maxDigits; digitIndex++) {
for (i = 0; i < arraySize; i++) {
bucketIndex = abs(array[i] / pow10) % 10
Append array[i] to buckets[bucketIndex]
}
arrayIndex = 0
for (i = 0; i < 10; i++) {
for (j = 0; j < buckets[i].size(); j++)
array[arrayIndex++] = buckets[i][j]
}
pow10 = 10 * pow10
Clear all buckets
}
}
答案 0 :(得分:0)
int buckets[][] = new int[10][arraySize]; // create array of 10 buckets