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
24 lines (24 loc) · 744 Bytes
/
code.js
File metadata and controls
24 lines (24 loc) · 744 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
logger._print('original array = [' + D.join(', ') + ']');
for (var i = 0; i < D.length - 1; i++) {
var minJ = i;
tracer._select(i)._wait();
for (var j = i + 1; j < D.length; j++) {
tracer._select(j)._wait();
if (D[j] < D[minJ]) {
minJ = j;
tracer._notify(j)._wait();
tracer._denotify(j);
}
tracer._deselect(j);
}
if (minJ != i) {
logger._print('swap ' + D[i] + ' and ' + D[minJ]);
var temp = D[i];
D[i] = D[minJ];
D[minJ] = temp;
tracer._notify(i, D[i])._notify(minJ, D[minJ])._wait();
tracer._denotify(i)._denotify(minJ);
}
tracer._deselect(i);
}
logger._print('sorted array = [' + D.join(', ') + ']');