nie-ii-year

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

commit eee8e61572eff1a02e4eb07ef16fd4d2bcbb91c8
parent 3f5f19f498d93cd2c354f65803af445ea65b69d1
Author: Agastya Chandrakant <acagastya@outlook.com>
Date:   Wed, 31 Jan 2018 09:35:05 +0530

Create recursive.js
Diffstat:
As4/algorithms/quicksort/recursive.js | 48++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+), 0 deletions(-)

diff --git a/s4/algorithms/quicksort/recursive.js b/s4/algorithms/quicksort/recursive.js @@ -0,0 +1,48 @@ +function quickSort(arr, low, high) { + if(low < high){ + pi = partition(arr, low, high); + quickSort(arr, low, pi - 1); + quickSort(arr, pi + 1, high); + } +} + +function partition(arr, low, high){ + var pivot = arr[high]; + var i = (low - 1); + for(var j = low; j <= high - 1; j++){ + if(arr[j] <= pivot){ + i++; + temp = arr[i]; + arr[i] = arr[j]; + arr[j] = temp; + } + } + temp = arr[i + 1]; + arr[i + 1] = arr[high]; + arr[high] = temp; + return i + 1; +} + +// var size; +// do{ +// print("Enter array size: "); +// size = readline(); +// size = parseInt(size); +// if(size % 1 !== 0 || size < 1) +// print("Invalid size, try again."); +// }while (size % 1 !== 0 || size < 1); +// +// array = []; +// array.length = size; +// print("Enter array elements: "); +// +// for(var i = 0; i < size; i++) +// array[i] = readline(); + +array = []; +for(var i = 10; i >= 0; i--) + array.push(i); + +print(array); +quickSort(array, 0, array.length - 1); +print(array);