<スクリプト>
Array.prototype.swap = function(i, j)
{
var temp = this[i];
this[i] = this[j];
this[j] = 温度;
}
Array.prototype.bubbleSort = function()
{
for (var i = this.length - 1; i > 0; --i)
{
for (var j = 0; j {
if (this[j] > this[j 1]) this.swap(j, j 1);
}
}
}
Array.prototype.selectionSort = function()
{
for (var i = 0; i < this.length; i)
{
var インデックス = i;
for (var j = i 1; j
{
if (this[j] < this[index])index = j;
}
this.swap(i,index);
}
}
Array.prototype.insertionSort = function()
{
for (var i = 1; i < this.length; i)
{
var j = i, value = this[i];
while (j > 0 && this[j - 1] > value)
{
this[j] = this[j - 1];
--j;
}
this[j] = 値;
}
}
Array.prototype.shellSort = function()
{
for (var step = this.length >> 1; step > 0; step >>= 1)
{
for (var i = 0; i < step; i)
{
for (var j = i step; j {
var k = j, value = this[j];
while (k >= ステップ && this[k - ステップ] > 値)
{
this[k] = this[k - ステップ];
k -= ステップ;
}
this[k] = 値;
}
}
}
}
Array.prototype.quickSort = function(s, e)
{
if (s == null) s = 0;
if (e == null) e = this.length - 1;
if (s >= e) return;
this.swap((s e) >> 1, e);
var インデックス = s - 1;
for (var i = s; i {
if (this[i] }
this.quickSort(s,index - 1);
this.quickSort(index 1, e);
}
Array.prototype.stackQuickSort = function()
{
var stack = [0, this.length - 1];
while (stack.length > 0)
{
var e = stack.pop(), s = stack.pop();
if (s >= e) 続行;
this.swap((s e) >> 1, e);
var インデックス = s - 1;
for (var i = s; i {
if (this[i] }
stack.push(s, インデックス - 1, インデックス 1, e);
}
}
Array.prototype.mergeSort = function(s, e, b)
{
if (s == null) s = 0;
if (e == null) e = this.length - 1;
if (b == null) b = new Array(this.length);
if (s >= e) return;
var m = (s e) >> 1;
this.mergeSort(s, m, b);
this.mergeSort(m 1, e, b);
for (var i = s, j = s, k = m 1; i {
b[i] = this[(k > e || j }
for (var i = s; i }
Array.prototype.heapSort = function()
{
for (var i = 1; i < this.length; i)
{
for (var j = i, k = (j - 1) >> 1; k >= 0; j = k, k = (k - 1) >> 1)
{
if (this[k] >= this[j]) ブレーク;
this.swap(j, k);
}
}
for (var i = this.length - 1; i > 0; --i)
{
this.swap(0, i);
for (var j = 0, k = (j 1) {
if (k == i || this[k] if (this[k] this.swap(j, k);
}
}
}
function generated()
{
var max = parseInt(txtMax.value), count = parseInt(txtCount.value);
if (isNaN(max) || isNaN(count))
{
alert("个数と最大值必须是一整数");
戻る;
}
var array = [];
for (var i = 0; i txtInput.value = array.join("n");
txtOutput.value = "";
}
関数デモ(タイプ)
{
var array = txtInput.value == "" ? [] : txtInput.value.replace().split("n");
for (var i = 0; i var t1 = 新しい日付();
eval("array." type "Sort()");
var t2 = 新しい日付();
lblTime.innerText = t2.valueOf() - t1.valueOf();
txtOutput.value = array.join("n");
}