So I'm trying to implement this pseudo-code for the radix sort and don't understand how to create a 2D ArrayList that this code is implying must be created. I've looked at other posts on creating a 2D ArrayList but don't understand how to properly implement it in this situation. Any help would be much appreciated.
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
}
}
int buckets[][] = new int[10][arraySize]; // create array of 10 buckets
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.