We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
桶排序思想:
function insertionSort(array) { for (let i = 1; i < array.length; i++) { let j = i let target = array[j] while (j > 0 && array[j - 1] > target) { array[j] = array[j - 1] j-- } array[j] = target } return array } function bucketSort(array, size = 10) { let min = array[0]; let max = array[0]; for (let i = 1; i < array.length; i++) { // {4} if (array[i] < min) { min = array[i]; } else if (array[i] > max) { max = array[i]; } } const count = Math.floor((max - min) / size) + 1 const buckets = [] for (let i = 0; i < count; i++) { buckets.push([]) } array.forEach(item => { const num = Math.floor((item - min) / size) buckets[num].push(item) }) const result = [] buckets.forEach(bucket => { result.push(...insertionSort(bucket)) }) return result } console.log(bucketSort([2, 1, 3, 100000000000000000000], 10000000000000000))
The text was updated successfully, but these errors were encountered:
No branches or pull requests
桶排序思想:
The text was updated successfully, but these errors were encountered: