diff --git a/algorithm/sorting/bubble/basic/code.js b/algorithm/sorting/bubble/basic/code.js index e48fd467..d445ca69 100644 --- a/algorithm/sorting/bubble/basic/code.js +++ b/algorithm/sorting/bubble/basic/code.js @@ -7,13 +7,13 @@ do { swapped = false; tracer._select(N - 1); for (var i = 1; i < N; i++) { + tracer._notify(i - 1, i); if (D[i - 1] > D[i]) { tracer._print('swap ' + D[i - 1] + ' and ' + D[i]); var temp = D[i - 1]; D[i - 1] = D[i]; D[i] = temp; swapped = true; - tracer._notify(i - 1, i); } } tracer._deselect(N - 1); diff --git a/algorithm/sorting/quick/basic/code.js b/algorithm/sorting/quick/basic/code.js index 84419726..781a4a9c 100644 --- a/algorithm/sorting/quick/basic/code.js +++ b/algorithm/sorting/quick/basic/code.js @@ -17,11 +17,11 @@ function partition(low, high) { var temp; for (var j = low; j < high; j++) { + tracer._notify(i, j); if (D[j] <= pivot) { temp = D[i]; D[i] = D[j]; D[j] = temp; - tracer._notify(i, j); i++; } } diff --git a/algorithm/sorting/selection/basic/code.js b/algorithm/sorting/selection/basic/code.js index efeefe59..d5b68323 100644 --- a/algorithm/sorting/selection/basic/code.js +++ b/algorithm/sorting/selection/basic/code.js @@ -5,11 +5,9 @@ for (var i = 0; i < D.length - 1; i++) { var minJ = i; tracer._select(i); for (var j = i + 1; j < D.length; j++) { - if (D[j] < D[minJ]) { - tracer._select(j); - minJ = j; - tracer._deselect(j); - } + tracer._select(j); + if (D[j] < D[minJ]) minJ = j; + tracer._deselect(j); } if (minJ != i) { tracer._print('swap ' + D[i] + ' and ' + D[minJ]);
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: