<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>ArrayList</title>
</head>
<body>
<script>
function ArrayList() {
//属性
this.array = [];
//
ArrayList.prototype.insert = function (item) {
this.array.push(item);
};
ArrayList.prototype.toString = function (item) {
return this.array.join("-");
};
ArrayList.prototype.swap = function (m, n) {
var temp = this.array[m];
this.array[m] = this.array[n];
this.array[n] = temp;
};
ArrayList.prototype.bubblesort = function (item) {
//
var length = this.array.length;
for (var i = 0; i < length-1; i++) {
if (this.array[i] < this.array[i + 1]) {
this.swap(i,i+1)
}
}
};
ArrayList.prototype.selectionSort = function () {
var length = this.array.length;
for(var j=0;j<length-1;j++){
var min=0
for(var i=main+1;i<length;i++){
if(this.array[min]>this.array[i]){
min=i
}
}
this.swap(min,j)
}
}
}
</script>
</body>
</html>