Skip to content

Commit 448eaf7

Browse files
committed
Merge pull request algorithm-visualizer#32 from parkjs814/revert-30-fix/sorting
Revert "Sorting time complexity"
2 parents f86e3d4 + 84ddbaf commit 448eaf7

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

algorithm/sorting/bubble/basic/code.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ do {
77
swapped = false;
88
tracer._select(N - 1);
99
for (var i = 1; i < N; i++) {
10-
tracer._notify(i - 1, i);
1110
if (D[i - 1] > D[i]) {
1211
tracer._print('swap ' + D[i - 1] + ' and ' + D[i]);
1312
var temp = D[i - 1];
1413
D[i - 1] = D[i];
1514
D[i] = temp;
1615
swapped = true;
16+
tracer._notify(i - 1, i);
1717
}
1818
}
1919
tracer._deselect(N - 1);

algorithm/sorting/quick/basic/code.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ function partition(low, high) {
1717
var temp;
1818

1919
for (var j = low; j < high; j++) {
20-
tracer._notify(i, j);
2120
if (D[j] <= pivot) {
2221
temp = D[i];
2322
D[i] = D[j];
2423
D[j] = temp;
24+
tracer._notify(i, j);
2525
i++;
2626
}
2727
}

algorithm/sorting/selection/basic/code.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ for (var i = 0; i < D.length - 1; i++) {
55
var minJ = i;
66
tracer._select(i);
77
for (var j = i + 1; j < D.length; j++) {
8-
tracer._select(j);
9-
if (D[j] < D[minJ]) minJ = j;
10-
tracer._deselect(j);
8+
if (D[j] < D[minJ]) {
9+
tracer._select(j);
10+
minJ = j;
11+
tracer._deselect(j);
12+
}
1113
}
1214
if (minJ != i) {
1315
tracer._print('swap ' + D[i] + ' and ' + D[minJ]);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

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:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy