New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Radix Sort #37
Comments
I did not understand what you are trying to say here, there is a Radix Sort algorithm here, maybe you could look into that and draw parallel between them? |
now i am struck at |
NV I i got the solution |
I am watching dsa js tutorial and implementing in on dart currently on radix sort
//radix sort
import 'dart:math' as Math;
main() {
}
getDigitNum(int n, int i) {
// return ((n / 100).round() %10);
// var cal = (n.abs() / Math.pow(10, =i)) % 10;
var cal = (n.round().abs() / Math.pow(10, i)) % 10;
// var cal = (n / 100)%10;
return cal.round();
}
digitCount(int number) {
if (number == 0) {
return 1;
}
return (number.abs().toString().length);
}
mostDigits(List number) {
var maxDigits = 0;
for (var i = 0; i < number.length; i++) {
maxDigits = Math.max(maxDigits, digitCount(number[i]));
}
return maxDigits;
}
radixSort(List nums) {
var maxDightCount = mostDigits(nums);
for (var k = 0; k < maxDightCount; k++) {
List digitBuckets = List.from({});//confused here
}
}
//here is the js codefunction getDigit(num, i) {
return Math.floor(Math.abs(num) / Math.pow(10, i)) % 10;
}
function digitCount(num) {
if (num === 0) return 1;
return Math.floor(Math.log10(Math.abs(num))) + 1;
}
function mostDigits(nums) {
let maxDigits = 0;
for (let i = 0; i < nums.length; i++) {
maxDigits = Math.max(maxDigits, digitCount(nums[i]));
}
return maxDigits;
}
function radixSort(nums){
let maxDigitCount = mostDigits(nums);
for(let k = 0; k < maxDigitCount; k++){
let digitBuckets = Array.from({length: 10}, () => []);
for(let i = 0; i < nums.length; i++){
let digit = getDigit(nums[i],k);
digitBuckets[digit].push(nums[i]);
}
nums = [].concat(...digitBuckets);
}
return nums;
}
radixSort([23,345,5467,12,2345,9852])
//i just want help this part below js code
//dart code
List digitBuckets = List.from({});//confused here
The text was updated successfully, but these errors were encountered: