如下所示
复制代码代码如下:
<! Doctype html public "-// w3c // dtd html 4.01 transitório // pt" "http://www.w3.org/tr/html4/loose.dtd">
<html>
<head>
<Title> Novo documento </title>
<meta name = "generator" content = "editplus">
<meta name = "autor" content = "">
<meta name = "Keywords" content = "">
<meta name = "description" content = "">
<script type = "text/javascript">
<!-
função getcard (m) {
var ret = [], rnd;
for (var i = 0; i <m; i ++) {
rnd = math.floor (math.random ()*(i+0,9999));
ret [i] = ret [rnd];
ret [rnd] = i
}
retornar ret;
}
var dados = [];
{
for (var i = 0; i <100; i ++) {
data.push (getcard (10));
}
}
// 二维数据排序
função mysort (array, col, ord, b, e) {
if (Array.Length == 0) retornar;
//document.write ("排序前"+array);
var t = [], s, i, curcol = col [0];
para (i = b; i <e; i ++) {
s = new String (Array [i] [Curcol]);
s._obj = matriz [i];
t.push (s)
}
t.sort ();
if (ord [0] == "des") {
t. reverse ();
}
para (i = 0; i <e - b; i ++) {
//document.write ("<br/>");
//document.write(ArrayZi]);
//document.write ("<br/>");
//document.write(t[i ]._obj);
//document.write ("<br/>");
//document.write(tativamente._obj == Array [b+i]);
array [b+i] = t [i] ._ obj;
}
//document.write ("排序后 ==================== <br/>")
// imprimir (matriz);
var começo, fim;
if (col.length> 1) {
col.shift ();
ord.shift ();
begin = b;
for (i = b; i <e - b - 1; i ++) {
if (matriz [i] [curcol]! = Array [i+1] [curcol]) {
fim = i+1;
//document.write("begin="+begin+"end="+nd+ "<br/>");
Mysort (Array, Col, Ord, Begin, End);
BEGIN = END;
}
}
if (comece! = e) {
Mysort (Array, Col, Ord, Begin, E);
}
}
//document.write ("<br/>");
//document.write ("排序后"+array);
}
função print (dados) {
for (var i = 0; i <data.length; i ++) {
document.write (dados [i]+"<br/>");
}
}
document.write ("排序前 ==================== <br/>");
impressão (dados);
var b = new Date (). getTime () ;;
mysort (dados, [0,1,2], ['ASC', 'DES', 'ASC'], 0, Data.length);
document.write ("用时"+(new Date (). gettime () - b));
document.write ("排序后 ==================== <br/>")
impressão (dados);
//->
</script>
</head>
<Body>
</body>
</html>