|
|
|
@ -20,9 +20,9 @@ QuickSort.prototype.instruct = function() { |
|
|
|
|
*/ |
|
|
|
|
QuickSort.prototype.sort = function(arr, start, end) { |
|
|
|
|
if (end - start <= 0) { |
|
|
|
|
// this.instruct('highlight', true, end)
|
|
|
|
|
// .instruct('message1', true, 'Start: ' + start)
|
|
|
|
|
// .instruct('message2', true, 'End: ' + end)
|
|
|
|
|
// this.instruct('highlight', 500, end)
|
|
|
|
|
// .instruct('message1', 500, 'Start: ' + start)
|
|
|
|
|
// .instruct('message2', 500, 'End: ' + end)
|
|
|
|
|
return arr; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -34,29 +34,29 @@ QuickSort.prototype.sort = function(arr, start, end) { |
|
|
|
|
var tmp; |
|
|
|
|
|
|
|
|
|
this//.instruct('initSection', left, right)
|
|
|
|
|
.instruct('marker1', true, left, 'L') |
|
|
|
|
.instruct('marker2', true, right, 'R'); |
|
|
|
|
.instruct('marker1', 500, left, 'L') |
|
|
|
|
.instruct('marker2', 500, right, 'R'); |
|
|
|
|
// .instruct('unhighlight')
|
|
|
|
|
// .instruct('highlight', true, pivot)
|
|
|
|
|
// .instruct('message3', false, 'Pivot value: ' + pivotval);
|
|
|
|
|
// .instruct('highlight', 500, pivot)
|
|
|
|
|
// .instruct('message3', 500, 'Pivot value: ' + pivotval);
|
|
|
|
|
|
|
|
|
|
while (left <= right) { |
|
|
|
|
while (arr[left].value < pivotval) { |
|
|
|
|
left++; |
|
|
|
|
|
|
|
|
|
this.comparisons++; |
|
|
|
|
this.instruct('marker1', true, left) |
|
|
|
|
.instruct('message1', false, 'Left: ' + left) |
|
|
|
|
.instruct('stats1', false, 'Comparisons: ' + this.comparisons) |
|
|
|
|
this.instruct('marker1', 500, left) |
|
|
|
|
.instruct('message1', 500, 'Left: ' + left) |
|
|
|
|
.instruct('stats1', 500, 'Comparisons: ' + this.comparisons) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
while (arr[right].value > pivotval) { |
|
|
|
|
right--; |
|
|
|
|
|
|
|
|
|
this.comparisons++; |
|
|
|
|
this.instruct('marker2', true, right) |
|
|
|
|
.instruct('message2', false, 'Right: ' + right) |
|
|
|
|
.instruct('stats1', false, 'Comparisons: ' + this.comparisons) |
|
|
|
|
this.instruct('marker2', 500, right) |
|
|
|
|
.instruct('message2', 500, 'Right: ' + right) |
|
|
|
|
.instruct('stats1', 500, 'Comparisons: ' + this.comparisons) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (left <= right) { |
|
|
|
@ -69,11 +69,11 @@ QuickSort.prototype.sort = function(arr, start, end) { |
|
|
|
|
|
|
|
|
|
this.swaps++; |
|
|
|
|
this//.instruct('swap', left, right)
|
|
|
|
|
.instruct('stats2', false, 'Swaps: ' + this.swaps) |
|
|
|
|
.instruct('message1', false, 'Left: ' + left) |
|
|
|
|
.instruct('message2', false, 'Right: ' + right) |
|
|
|
|
.instruct('marker1', true, left) |
|
|
|
|
.instruct('marker2', true, right); |
|
|
|
|
.instruct('stats2', 500, 'Swaps: ' + this.swaps) |
|
|
|
|
.instruct('message1', 500, 'Left: ' + left) |
|
|
|
|
.instruct('message2', 500, 'Right: ' + right) |
|
|
|
|
.instruct('marker1', 500, left) |
|
|
|
|
.instruct('marker2', 500, right); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|