
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Radix sort in Javascript?
The radix sort algorithm distributes integers into buckets based on a number's significant digit or value (the radix). The radix is based on the number system of the values of the arrays. Let us look at how it can be implemented −
Example
function radixSort(arr) { // Find the max number and multiply it by 10 to get a number // with no. of digits of max + 1 const maxNum = Math.max(...arr) * 10; let divisor = 10; while (divisor < maxNum) { // Create bucket arrays for each of 0-9 let buckets = [...Array(10)].map(() => []); // For each number, get the current significant digit and put it in the respective bucket for (let num of arr) { buckets[Math.floor((num % divisor) / (divisor / 10))].push(num); } // Reconstruct the array by concatinating all sub arrays arr = [].concat.apply([], buckets); // Move to the next significant digit divisor *= 10; } return arr; } console.log(radixSort([5,3,88,235,65,23,4632,234]))
Output
[ 3, 5, 23, 65, 88, 234, 235, 4632 ]
- Related Articles
- Radix sort - JavaScript
- Radix Sort
- C Program for Radix Sort
- Java Program for Radix Sort
- C++ Program to Implement Radix Sort
- Golang program to implement radix sort
- What is JSlint error "missing radix parameter" in JavaScript?
- Merge sort vs quick sort in Javascript
- Natural Sort in JavaScript
- Implementing Priority Sort in JavaScript
- Case-sensitive sort in JavaScript
- Implementing counting sort in JavaScript
- Convert BigInteger into another radix number in Java
- JavaScript Sort() method
- Parse and format to arbitrary radix

Advertisements