naive merging implementation
This commit is contained in:
parent
702296eb79
commit
6611378590
|
@ -55,6 +55,28 @@
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ArrRef} a
|
||||
* @param {ArrRef} b
|
||||
*/
|
||||
function merge(a, b) {
|
||||
let index = 0,
|
||||
compr = 0;
|
||||
|
||||
while (index < a.length && compr < b.length) {
|
||||
if (a.at(index) < b.at(compr)) {
|
||||
data[index + compr] = a.at(index);
|
||||
index++;
|
||||
} else {
|
||||
data[index + compr] = b.at(compr);
|
||||
compr++;
|
||||
}
|
||||
}
|
||||
|
||||
while (index < a.length) (data[index + compr] = a.at(index)), index++;
|
||||
while (compr < b.length) (data[index + compr] = b.at(compr)), compr++;
|
||||
}
|
||||
|
||||
/** Render a single frame of the sorting algorithm at a time on the canvas. */
|
||||
function animate() {
|
||||
// Clear canvas with black background
|
||||
|
|
Loading…
Reference in New Issue
Block a user