Skip to content

Instantly share code, notes, and snippets.

@13hoop
Created March 16, 2017 04:29
Show Gist options
  • Save 13hoop/7bf25a14f0f0910ca06dc3f1560e2942 to your computer and use it in GitHub Desktop.
Save 13hoop/7bf25a14f0f0910ca06dc3f1560e2942 to your computer and use it in GitHub Desktop.
insertSort
var is = function(a) {
console.log('原' + a)
for (var i=1; i < a.length; i++) {
var temp = a[i]
var j = i
while(a[j] < a[j-1] && j > 0) {
console.log(' -'+ i + '- ' + a[j] + ' swap ' + a[j-1])
a[j] = a[j-1]
a[j-1] = temp
j--
}
console.log("第" + i + "次" + a)
}
}
var a = [8,5,7,1,9,3]
is(a)
@13hoop
Copy link
Author

13hoop commented Mar 16, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment