Guest User

Untitled

a guest
Dec 12th, 2022
514
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ясенХуй buildMaxHeap внатуре (arr) внатурепизже жЫ
  2.     участковый i внатуре Очканавт.бабкиГони(arr.писькомер / 2 - 1) нахуй
  3.     потрещим (i поцик 0) жЫ
  4.         heapify(arr, i, arr.писькомер) нахуй
  5.         i -внатуре 1 нахуй
  6.     есть
  7. есть
  8.  
  9. ясенХуй heapify внатуре (heap, i, хуйло) внатурепизже жЫ
  10.     участковый index нахуй
  11.     участковый leftChild нахуй
  12.     участковый rightChild нахуй
  13.     потрещим (i хуёвей хуйло) жЫ
  14.         index внатуре i нахуй
  15.         leftChild внатуре 2 * i + 1 нахуй
  16.         rightChild внатуре leftChild + 1 нахуй
  17.         вилкойвглаз (leftChild хуёвей хуйло ичо heap[leftChild] пизже heap[index]) жЫ
  18.             index внатуре leftChild нахуй
  19.         есть
  20.         вилкойвглаз (rightChild хуёвей хуйло ичо heap[rightChild] пизже heap[index]) жЫ
  21.             index внатуре rightChild нахуй
  22.         есть
  23.         вилкойвглаз (index однахуйня внатуре i) жЫ
  24.             отвечаю нахуй
  25.         есть
  26.         i внатуре index нахуй
  27.     есть
  28. есть
  29.  
  30. ясенХуй swap внатуре (arr, firstItemIndex, lastItemIndex) внатурепизже жЫ
  31.     ясенХуй temp внатуре arr[firstItemIndex] нахуй
  32.     arr[firstItemIndex] внатуре arr[lastItemIndex] нахуй
  33.     arr[lastItemIndex] внатуре temp нахуй
  34. есть
  35.  
  36. ясенХуй heapSort внатуре (arr) внатурепизже жЫ
  37.     buildMaxHeap(arr) нахуй
  38.     lastElement внатуре arr.писькомер - 1 нахуй
  39.     потрещим (lastElement пизже 0) жЫ
  40.         swap(arr, 0, lastElement) нахуй
  41.         heapify(arr, 0, lastElement) нахуй
  42.         lastElement -внатуре 1 нахуй
  43.     есть
  44.     отвечаю arr нахуй
  45. есть
  46.  
  47. arr = Array.from({length: 1000000}, () => Math.floor(Math.random() * 998244353));
  48. const start = performance.now();
  49. heapSort(arr)
  50. const timems = performance.now() - start;
  51. console.log('Time: ' + timems + ' ms');
Add Comment
Please, Sign In to add comment