Skip to content

Commit 3693fc1

Browse files
committed
Merge branch 'gh-pages' of https://github.com/johnhuichen/AlgorithmVisualizer into johnhuichen-gh-pages
2 parents e7cace5 + bd0d44b commit 3693fc1

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

algorithm/sorting/comb/basic/code.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ do{
1515
swapped = false; // initialize swapped
1616
// a single comb over the input list
1717
for( var i=0; i+gap < N; i++ ){
18+
tracer._select(i)._select(i+gap)._wait();
19+
1820
if( D[i] > D[i+gap] ){
1921
logger._print('swap ' + D[i] + ' and ' + D[i+gap]); // log swap event
2022

@@ -27,5 +29,6 @@ do{
2729

2830
swapped = true; // Flag swapped has happened and list is not guaranteed sorted
2931
}
32+
tracer._deselect(i)._deselect(i+gap);
3033
} // End of combing
3134
} while( gap!=1 || swapped )

algorithm/sorting/cycle/basic/code.js

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,43 @@ var writes = 0;
44
var pos;
55
var item;
66
var temp;
7-
for( var cycleStart=0; cycleStart<=N-2; cycleStart++ ){
7+
for(var cycleStart=0; cycleStart<=N-2; cycleStart++ ){
88
item = D[cycleStart];
99
pos = cycleStart;
10-
for( var i=cycleStart+1; i<=N-1; i++ ){
10+
tracer._select(cycleStart);
11+
12+
for(var i=cycleStart+1; i<=N-1; i++ ){
13+
tracer._select(i)._wait()._deselect(i);
1114
if( D[i]<item ){
1215
pos++;
1316
}
1417
}
1518
if( pos == cycleStart ){
19+
tracer._deselect(cycleStart);
1620
continue;
1721
}
1822
while( item == D[pos] ){
1923
pos++;
2024
}
25+
2126
temp = D[pos];
2227
D[pos] = item;
2328
item = temp;
2429

25-
logger._print( 'Rewrite '+D[pos]+' to index '+pos );
26-
30+
if( pos !== cycleStart ){
31+
logger._print( 'Rewrite '+D[pos]+' to index '+pos+'; the next value to rewrite is '+item );
32+
}else{
33+
logger._print( 'Rewrite '+D[pos]+' to index '+pos);
34+
}
35+
tracer._select(pos)._wait()._deselect(pos);
2736
tracer._notify(pos, D[pos])._notify(cycleStart, D[cycleStart])._wait();
28-
tracer._denotify(pos)._denotify(pos);
29-
37+
tracer._denotify(pos)._denotify(cycleStart);
3038

3139
while( pos != cycleStart ){
3240
pos = cycleStart;
41+
3342
for( i=cycleStart+1; i<=N-1; i++ ){
43+
tracer._select(i)._wait()._deselect(i);
3444
if( D[i]<item ){
3545
pos++;
3646
}
@@ -39,14 +49,19 @@ for( var cycleStart=0; cycleStart<=N-2; cycleStart++ ){
3949
while( item == D[pos] ){
4050
pos++;
4151
}
52+
4253
temp = D[pos];
4354
D[pos] = item;
4455
item = temp;
4556

46-
logger._print( 'Rewrite '+D[pos]+' to index '+pos );
47-
57+
if( pos !== cycleStart ){
58+
logger._print( 'Rewrite '+D[pos]+' to index '+pos+'; the next value to rewrite is '+item );
59+
}else{
60+
logger._print( 'Rewrite '+D[pos]+' to index '+pos);
61+
}
62+
tracer._select(pos)._wait()._deselect(pos);
4863
tracer._notify(pos, D[pos])._notify(cycleStart, D[cycleStart])._wait();
49-
tracer._denotify(pos)._denotify(pos);
64+
tracer._denotify(pos)._denotify(cycleStart);
5065

5166
writes++;
5267
}

0 commit comments

Comments
 (0)