Guest User

Untitled

a guest
Nov 19th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. var arr = [];
  2. var n = 1000 * 1000 * 10;
  3. for (var i = 0; i < n; i++) {
  4. //arr.push(Math.floor(Math.random() * n));
  5. arr.push(i);
  6. }
  7. arr[0] = 5000;
  8. arr[1] = 100;
  9.  
  10.  
  11. function sort(arr)
  12. {
  13. for(var index = 1 ; index < arr.length ; index++){
  14. var temp = arr[index];
  15. var aux = index - 1;
  16.  
  17. while( (aux >= 0) && ( arr[aux] > temp) ) {
  18. arr[aux+1] = arr[aux];
  19. aux--;
  20. }
  21. arr[aux + 1] = temp;
  22. }
  23. }
  24.  
  25. sort(arr); //insertion sort, O(n) in this case, very fast!
  26. //arr.sort((a,b) => (a - b)); //merge sort - n log n, so far so good.
  27. console.log(arr[0], arr[100], arr[200], arr[500]);
Add Comment
Please, Sign In to add comment