forked from algorithm-visualizer/algorithm-visualizer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.js
More file actions
23 lines (23 loc) · 631 Bytes
/
code.js
File metadata and controls
23 lines (23 loc) · 631 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
tracer._print('original array = [' + D.join(', ') + ']');
tracer._sleep(1000);
tracer._pace(500);
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);
}
}
if (minJ != i) {
tracer._print('swap ' + D[i] + ' and ' + D[minJ]);
var temp = D[i];
D[i] = D[minJ];
D[minJ] = temp;
tracer._notify(i, minJ);
}
tracer._deselect(i);
}
tracer._print('sorted array = [' + D.join(', ') + ']');