/
index.min.js
1 lines (1 loc) · 1.6 KB
/
index.min.js
1
"use strict";function isBrowser(){return("object"!=typeof process||"function"!=typeof require)&&"function"!=typeof importScripts&&("object"==typeof window||void 0)}function bucketSort(r,t=10){if(r.length<=1)return r;var o,e=Math.min(...r),n=Math.max(...r),f=Math.floor((n-e)/t),a=Array.from({length:t},()=>[]);for(o of r)a[Math.floor((o-e)/f)].push(o);var i,c=[];for(i of a)c.push(...i.sort((r,t)=>r-t));return c}function radixSort(t){var r=Math.max(...t);let o=1;for(;o<r;){var e=Array.from({length:10},()=>[]);for(const f of t)e[Math.floor(Math.abs(f)/o)%10].push(f);let r=0;for(const a of e)for(const i of a)t[r]=i,r++;o*=10}var n=t.filter(r=>0<=r);return t.filter(r=>r<0).reverse().concat(n)}function heapify(r,t,o){let e=o;var n=2*o+1,f=2*o+2;n<t&&r[n]>r[e]&&(e=n),(e=f<t&&r[f]>r[e]?f:e)!==o&&([r[o],r[e]]=[r[e],r[o]],heapify(r,t,e))}function heapSort(t){var o=t.length;for(let r=Math.floor(o/2)-1;0<=r;r--)heapify(t,o,r);for(let r=o-1;0<r;r--)[t[0],t[r]]=[t[r],t[0]],heapify(t,r,0);return t}function mergeSort(r){var t,o;return r.length<=1?r:(t=Math.floor(r.length/2),o=r.slice(0,t),r=r.slice(t),merge(mergeSort(o),mergeSort(r)))}function merge(r,t){var o=[];let e=0,n=0;for(;e<r.length&&n<t.length;)r[e]<t[n]?(o.push(r[e]),e++):(o.push(t[n]),n++);return o.concat(r.slice(e)).concat(t.slice(n))}function quickSort(t){if(t.length<=1)return t;var o=t[Math.floor(t.length/2)],e=[],n=[];for(let r=0;r<t.length;r++)r!==Math.floor(t.length/2)&&(t[r]<o?e:n).push(t[r]);return[...quickSort(e),o,...quickSort(n)]}isBrowser()||(module.exports={quickSort:quickSort,mergeSort:mergeSort,heapSort:heapSort,radixSort:radixSort,bucketSort:bucketSort});