Created
February 18, 2015 10:45
-
-
Save timakin/b4bff82702aae60d3951 to your computer and use it in GitHub Desktop.
文系が学ぶコンピューターサイエンス╭( ・ㅂ・)و ̑̑:第4回【コームソート】 ref: http://qiita.com/timakin/items/ae7de80a635fa033126b
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
combSort: function(data) { | |
var N = data.length; | |
var gap = N; | |
while((gap > 1) || flag) { | |
// 収縮率(間隔調整の度合い)は1.3。 | |
var gap = gap*10/13; | |
if (gap < 1) { gap = 1 }; | |
var flag = 0; | |
for (var i = 0; i < N - gap; i++) { | |
if (data[i] > data[i+gap]) { | |
this.swap(data, i, i+gap); | |
flag = 1; | |
} | |
} | |
} | |
return data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment