function swap(arr, x, y){
let temp = arr[x];
arr[x] = arr[y];
arr[y] = temp;
}
function bubbleSort(arr){
for(let i=0; i<arr.length-1; ++i){
for(let j=0; j<arr.length-i-1; ++j){
if(arr[j] > arr[j+1]) swap(arr, j, j+1)
}
}
}
function quickSort(arr, left, right){
if(left >= right) return;
function partition(arr, left, right){
let k = arr[left];
while(left < right){
while(arr[right] >= k && left < right) --right;
swap(arr, left, right);
while(arr[left] < k && left < right) ++left;
swap(arr, left, right);
}
arr[left] = k;
return left;
}
const pos = partition(arr, left, right);
quickSort(arr, left, pos-1);
quickSort(arr, pos+1, right);
}
function heapSort(arr){
function buildHeap(arr){
let heapSize = arr.length;
for(let i=Math.floor(heapSize / 2 - 1); i>=0; --i){
heapify(arr, i, heapSize);
}
}
function heapify(arr, index, heapSize){
while(true){
let minIndex = index;
if(2*index + 1 < heapSize && arr[2*index + 1] > arr[minIndex]){
minIndex = 2*index + 1;
}
if(2*(index + 1) < heapSize && arr[2*(index + 1)] > arr[minIndex]){
minIndex = 2*(index + 1);
}
if(minIndex === index) return;
swap(arr, minIndex, index);
index = minIndex;
}
}
buildHeap(arr);
for(let i=arr.length-1; i>=0; --i){
swap(arr, 0, i);
heapify(arr, 0, i)
}
}