daily pastebin goal
17%
SHARE
TWEET

Untitled

a guest Sep 23rd, 2018 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function qs(vet)
  2. {
  3.     quickSort(vet, 0, vet.length - 1);
  4. }
  5.  
  6. function quickSort(vet, ini, fim)
  7. {
  8.     var i = ini;
  9.     var f = fim;
  10.     var m = Math.floor((i + f)/2);
  11.  
  12.     while(i < f)
  13.     {
  14.         while(vet[i] < vet[m])
  15.             i++;
  16.  
  17.         while(vet[f] > vet[m])
  18.             f--;
  19.  
  20.         if(i <= f)
  21.         {
  22.             var temp = vet[i];
  23.             vet[i] = vet[f];
  24.             vet[f] = temp;
  25.             i++;
  26.             f--;
  27.         }
  28.     }
  29.  
  30.     if(f > ini)
  31.         quickSort(vet, ini, f);
  32.  
  33.     if(i < fim)
  34.         quickSort(vet, i, fim);
  35. }
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