Created
October 13, 2017 12:56
-
-
Save Nick0603/06345700659801ecc555bad206083d1b to your computer and use it in GitHub Desktop.
收尋排序
This file contains 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
var nums = [2,7,4,6,3]; | |
var sort_nums = []; | |
console.log("排序前:"); | |
console.log(nums); | |
console.log("排序過程:"); | |
while( nums.length>0){ | |
var min = Infinity; | |
var index = -1; | |
for(var j=0;j<nums.length;j++){ | |
if( nums[j] < min ){ | |
min = nums[j]; | |
index = j; | |
} | |
} | |
sort_nums.push(min); | |
nums.splice(index,1); | |
console.log(sort_nums); | |
} | |
console.log("排序後:"); | |
console.log(sort_nums); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment