SHARE
TWEET

Untitled

a guest Jan 24th, 2020 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //NOVO------------------------------------------------------------------------
  2. function partition(items, left, right) {
  3.     var pivot   = items[Math.floor((right + left) / 2)], //middle element
  4.         i       = left, //left pointer
  5.         j       = right; //right pointer
  6.     while (i <= j) {
  7.         while (items[i] < pivot) {
  8.             i++;
  9.         }
  10.         while (items[j] > pivot) {
  11.             j--;
  12.         }
  13.         if (i <= j) {
  14.             swap(items, i, j); //swap two elements
  15.             i++;
  16.             j--;
  17.         }
  18.     }
  19.     return i;
  20. }
  21. //STARo------------------------------------------------------------------------
  22. function partition(items, left, right) {
  23.   let pivot = items[Math.floor((right + left) / 2)], //middle element
  24.     i = left, //left pointer
  25.     j = right; //right pointer
  26.  
  27. while(i<j){
  28.     while (items[i] < pivot) {
  29.         i++;
  30.       }
  31.       while (items[j] > pivot) {
  32.           console.log(j)
  33.         j--;
  34.       }
  35.       if (i <= j) {
  36.         //    sawpping two elements})
  37.  
  38.         swap(items, i, j);
  39.         i++;
  40.         j--;
  41.       }
  42.     }
  43.  
  44.     return i;
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top