nie-ii-year

lab stuff from undergrad second year.
git clone http://git.hanabi.in/repos/nie-ii-year.git
Log | Files | Refs | LICENSE

recursive.js (977B)


      1 function quickSort(arr, low, high) {
      2   if(low < high){
      3     pi = partition(arr, low, high);
      4     quickSort(arr, low, pi - 1);
      5     quickSort(arr, pi + 1, high);
      6   }
      7 }
      8 
      9 function partition(arr, low, high){
     10   var pivot = arr[high];
     11   var i = (low - 1);
     12   for(var j = low; j <= high - 1; j++){
     13     if(arr[j] <= pivot){
     14       i++;
     15       temp = arr[i];
     16       arr[i] = arr[j];
     17       arr[j] = temp;
     18     }
     19   }
     20   temp = arr[i + 1];
     21   arr[i + 1] = arr[high];
     22   arr[high] = temp;
     23   return i + 1;
     24 }
     25 
     26 // var size;
     27 // do{
     28 //   print("Enter array size: ");
     29 //   size = readline();
     30 //   size = parseInt(size);
     31 //   if(size % 1 !== 0 || size < 1)
     32 //     print("Invalid size, try again.");
     33 // }while (size % 1 !== 0 || size < 1);
     34 //
     35 // array = [];
     36 // array.length = size;
     37 // print("Enter array elements: ");
     38 //
     39 // for(var i = 0; i < size; i++)
     40 //   array[i] = readline();
     41 
     42 array = [];
     43 for(var i = 10; i >= 0; i--)
     44   array.push(i);
     45 
     46 print(array);
     47 quickSort(array, 0, array.length - 1);
     48 print(array);