Advertisement
Peaser

javascript quicksort

Jul 9th, 2015
539
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function quicksort(arr) {
  2.   var i;
  3.   var len = arr.length;
  4.   var iter = 1;
  5.   while (iter < len) {
  6.     for (i = 0; i <= len; i++) {
  7.       if (i != (len - 1)) {
  8.         if (arr[i] > arr[i + 1]) {
  9.           var TEMP = arr[i + 1];
  10.           arr[i + 1] = arr[i];
  11.           arr[i] = TEMP;
  12.         }
  13.       }
  14.     }
  15.     iter++;
  16.   }
  17.   return arr;
  18. }
  19.  
  20. /**
  21.  * Minified one-liner.
  22.  *
  23.  * function quicksort(r){for(var f,n=r.length,o=1;n>o;){for(f=0;n>=f;f++)if(f!=n-1&&r[f]>r[f+1]){var t=r[f+1];r[f+1]=r[f],r[f]=t}o++}return r}
  24.  *
  25.  */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement