Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var arr = [];
- var n = 1000 * 1000 * 10;
- for (var i = 0; i < n; i++) {
- //arr.push(Math.floor(Math.random() * n));
- arr.push(i);
- }
- arr[0] = 5000;
- arr[1] = 100;
- function sort(arr)
- {
- for(var index = 1 ; index < arr.length ; index++){
- var temp = arr[index];
- var aux = index - 1;
- while( (aux >= 0) && ( arr[aux] > temp) ) {
- arr[aux+1] = arr[aux];
- aux--;
- }
- arr[aux + 1] = temp;
- }
- }
- sort(arr); //insertion sort, O(n) in this case, very fast!
- //arr.sort((a,b) => (a - b)); //merge sort - n log n, so far so good.
- console.log(arr[0], arr[100], arr[200], arr[500]);
Add Comment
Please, Sign In to add comment