|
|
|
@ -18,10 +18,8 @@ QuickSort.prototype = Object.create(Sorter.prototype); |
|
|
|
|
* |
|
|
|
|
*/ |
|
|
|
|
QuickSort.prototype.sort = function(arr, start, end) { |
|
|
|
|
if (end - start <= 0) { |
|
|
|
|
// this//.instruct(this.V.highlight, 500, end)
|
|
|
|
|
// .instruct(this.V.message, 0, 3, 'Start: ' + start)
|
|
|
|
|
// .instruct(this.V.message, 0, 4, 'End: ' + end)
|
|
|
|
|
if (end <= start) { |
|
|
|
|
// message: Left and Right have crossed, start sorting sublists.
|
|
|
|
|
return arr; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -43,6 +41,10 @@ QuickSort.prototype.sort = function(arr, start, end) { |
|
|
|
|
.instruct(this.V.unhighlight, 0) |
|
|
|
|
.instruct(this.V.highlight, 0, pivot) |
|
|
|
|
|
|
|
|
|
.instruct(this.V.fade, 0, -1, start - 1) |
|
|
|
|
.instruct(this.V.fade, 0, end + 1, arr.length) |
|
|
|
|
// Message: pivot chosen
|
|
|
|
|
|
|
|
|
|
.instruct(this.V.message, 0, 3, 'Sorting from [' + start + '] to [' + end + ']') |
|
|
|
|
.instruct(this.V.message, 0, 4, '') |
|
|
|
|
.instruct(this.V.message, 100, 5, ''); |
|
|
|
@ -69,14 +71,16 @@ QuickSort.prototype.sort = function(arr, start, end) { |
|
|
|
|
while (arr[right].value > pivotval) { |
|
|
|
|
this.comparisons++; |
|
|
|
|
this.V |
|
|
|
|
.instruct(this.V.message, 0, 5, `${arr[right].value} < ${pivotval}, decrement right`) |
|
|
|
|
.instruct(this.V.message, 0, 5, `${arr[right].value} > ${pivotval}, decrement right`) |
|
|
|
|
.instruct(this.V.message, 0, 1, 'Comparisons: ' + this.comparisons) |
|
|
|
|
.instruct(this.V.marker, 500, 2, right); |
|
|
|
|
|
|
|
|
|
right--; |
|
|
|
|
this.V.instruct(this.V.marker, 500, 2, right) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.V.instruct(this.V.message, 100, 5, `Right stop: ${arr[right].value} <= ${pivotval} `) |
|
|
|
|
this.V |
|
|
|
|
.instruct(this.V.message, 0, 5, `Right stop: ${arr[right].value} <= ${pivotval} `) |
|
|
|
|
.instruct(this.V.marker, 500, 2, right); |
|
|
|
|
|
|
|
|
|
if (left <= right) { |
|
|
|
|
tmp = arr[left]; |
|
|
|
@ -101,6 +105,7 @@ QuickSort.prototype.sort = function(arr, start, end) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.V |
|
|
|
|
.instruct(this.V.unfade, 0) |
|
|
|
|
.instruct(this.V.unhighlight, 0) |
|
|
|
|
.instruct(this.V.hideMarker, 0, 1) |
|
|
|
|
.instruct(this.V.hideMarker, 0, 2) |
|
|
|
|