Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
34 lines (28 loc) · 1.04 KB

File metadata and controls

34 lines (28 loc) · 1.04 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
logger._print('original array = [' + D.join(', ') + ']');
var N = D.length;
var swapped;
var gap = N; // initialize gap size
var shrink = 1.3; // set the gap shrink factor
do{
// update the gap value for the next comb.
gap = Math.floor( gap/shrink );
if( gap < 1 ){
// minimum gap is 1
gap = 1;
}
swapped = false; // initialize swapped
// a single comb over the input list
for( var i=0; i+gap < N; i++ ){
tracer._select(i)._select(i+gap)._wait();
if( D[i] > D[i+gap] ){
logger._print('swap ' + D[i] + ' and ' + D[i+gap]); // log swap event
var temp = D[i];
D[i] = D[i+gap];
D[i+gap] = temp;
tracer._notify(i, D[i])._notify(i+gap, D[i+gap])._wait();
tracer._denotify(i)._denotify(i+gap);
swapped = true; // Flag swapped has happened and list is not guaranteed sorted
}
tracer._deselect(i)._deselect(i+gap);
} // End of combing
} while( gap!=1 || swapped )
Morty Proxy This is a proxified and sanitized view of the page, visit original site.