Sorting algorithms
by Simplybj
HTML
<ul>
<li>Bubble sort</li>
<li>Selection sort</li>
<li> sort</li>
<li> sort</li>
<li> sort</li>
<li> sort</li>
<li> sort</li>
</ul>
JavaScript
for (var a = [], i = 0; i < 60; ++i) a[i] = i;
function shuffle(array) {
var tmp, current, top = array.length;
if (top)
while (--top) {
current = Math.floor(Math.random() * (top + 1));
tmp = array[current];
array[current] = array[top];
array[top] = tmp;
}
return array;
}
function BubbleSort(arr) {
let len = arr.length;
for (var i = 0; i < len; i++) {
for (var j = 0; j <= (len - i - 1); j++) {
if (arr[j] > arr[j + 1]) {
var temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
console.log(arr);
}
let tobeSort = shuffle(a);
var t0 = performance.now();
console.log(tobeSort);
BubbleSort(tobeSort);
var t1 = performance.now();
console.log("Call to doSomething took " + (t1 - t0) + " milliseconds.");
function TreeSort(arr)
{
}