I am trying to use recursive generator function to implement a visualization of a Merge Sort: Here is the code:
*oneStep() {
yield * this.mSort(0,dataSize-1);
yield true;
}
*mSort(l,r) {
console.log("Entering mSort with " + l + "," + r);
if (l <r) {
let m = floor((r-l)/2);
yield * this.mSort(l,m);
yield * this.mSort(m+1,r);
yield * this.merge(l,m,r);
}
yield true;
}
*merge(l,m,r) { .. code to merge the 2 sections }
The console logs show this:
Entering mSort with 0,49
Entering mSort with 0,24
Entering mSort with 0,12
Entering mSort with 0,6
Entering mSort with 0,3
Entering mSort with 0,1
Entering mSort with 0,0
So the initial yield* is working and recursing down the left hand side. But once it returns true, it doesn’t continue onto the next yield* for the right side, and I’m unsure why?