keeping track of return types mid-sort
This commit is contained in:
parent
bdf3e3437a
commit
eba7fac4db
|
@ -40,6 +40,22 @@
|
|||
/** @type {Job[]} */
|
||||
let queue = [];
|
||||
|
||||
/** Response type for the quicksort algorithm */
|
||||
class Response {
|
||||
/**
|
||||
* @param {boolean} done
|
||||
* @param {number|null} index
|
||||
* @param {number|null} start
|
||||
* @param {number|null} end
|
||||
*/
|
||||
constructor(done, index, start, end) {
|
||||
this.done = done;
|
||||
this.index = index;
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
}
|
||||
}
|
||||
|
||||
/** Represent a call to the quicksort algorithm. */
|
||||
class Job {
|
||||
/**
|
||||
|
@ -56,6 +72,10 @@
|
|||
this.index = start;
|
||||
this.compr = start;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Response|void}
|
||||
*/
|
||||
step() {
|
||||
if (this.start >= this.end - 1 || this.start < 0) return new Response(true, null, null, null);
|
||||
|
||||
|
@ -64,6 +84,8 @@
|
|||
this.array[this.end - 1],
|
||||
this.array[this.index]
|
||||
];
|
||||
|
||||
return new Response(false, this.index, this.start, this.end);
|
||||
}
|
||||
|
||||
if (this.array[this.compr] <= this.pivot) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user