image.png
charu.gif
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>插入排序</title>
</head>
<body>
<script>
var CArray = function () {
this.dataStore = [1,8,3,2,9,5,4,7];
this.insertSort = insertSort;
};
function insertSort(arr,index1,index2) {
var temp,inner;
for(var outer = 1;outer<this.dataStore.length;++outer){
temp = this.dataStore[outer];
inner = outer;
while (inner>0&&(this.dataStore[inner-1]>=temp)){
this.dataStore[inner] = this.dataStore[inner-1];
console.log("內(nèi)部數(shù)據(jù)",this.dataStore);
inner--;
}
this.dataStore[inner] = temp;
console.log("數(shù)據(jù)",this.dataStore);
}
}
var mynums = new CArray();
mynums.insertSort();
console.log(mynums.dataStore);
</script>
</body>
</html>
得到結(jié)果:
image.png
分割線
博主為咯學(xué)編程:父母不同意學(xué)編程速缨,現(xiàn)已斷絕關(guān)系;戀人不同意學(xué)編程锌妻,現(xiàn)已分手;親戚不同意學(xué)編程,現(xiàn)已斷絕來往;老板不同意學(xué)編程,現(xiàn)已失業(yè)三十年旬牲。仿粹。搁吓。。吭历。堕仔。如果此博文有幫到你歡迎打賞,金額不限晌区。摩骨。。