Skip to content

Commit

Permalink
Switch to using random to select for extend
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabau committed Oct 13, 2024
1 parent d3df6df commit 1c1eb9e
Showing 1 changed file with 4 additions and 19 deletions.
23 changes: 4 additions & 19 deletions gabau.github.io/src/pages/fun/SortVisPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,29 +204,14 @@ class ExtendedPartitionSortState extends PartitionSortState {

// only add parititions when the partitions are not sorted
addPartitions(): boolean {
return !this.sorted;
return true;
}

getNextStep(values: number[]): number[] | "finished" {
if (this.state === "checkingSorted") {
if (this.currPos >= this.end ||
this.frontPointer >= this.end ||
this.start >= this.end) {

// we have finished sorting this entire partition
this.state = "sorting";
this.sorted = true;
this.currPos = this.start + 1;
if (this.partitions.length === 0) return "finished";
return values;
} else if (values[this.currPos - 1] > values[this.currPos]) {
// need to sort partition
this.state = "sorting";
this.sorted = false;
this.currPos = this.start + 1;
return values;
}
this.currPos += 1;
this.state = "sorting";
if (this.frontPointer < this.end)
this.swap(values, this.frontPointer, Math.round(Math.random() * (this.end - 1 - this.start)) + this.start);
return values;
}
return super.getNextStep(values);
Expand Down

0 comments on commit 1c1eb9e

Please sign in to comment.