排序並記錄一個數組的下標

<!DOCTYPE html>html

<html>htm

<head>ip

<meta charset="UTF-8">it

<title>Insert title here</title>meta

<script>script

var c= new Array(); data

var orderdata = new Array(12,43,5,96);document

var orderLength = orderdata.length;new

var temp,tp;

for(var l =0;l<orderLength ;l++) c[l]=l;

for (var i=0;i<orderLength ;i++)

{

for (var j = 0; j < orderLength - i-1; j++)

{

if(orderdata[j] > orderdata[j+1])

temp = orderdata[j];

orderdata[j] = orderdata[j+ 1];

orderdata[j + 1] = temp;

tp = c [j];

c[j] = c[j+1];

c[j+1] = tp;

}

}

}

for(var m=0;m<orderLength;m++)

document.write(c[m]+" ");


</script>

</head>

<body>


</body>

</html>

相關文章
相關標籤/搜索