1 <html>
2 <head>
3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title></title>
5 <style type="text/css">
6 </style>
7 </head>
8 <body>
9 <script language="javascript">
10 /*冒泡排序的问题,面试考题*/
11 var arr=[44,58,6,21,3,7,15,36,1,785,62];//数组的定义方式var arr=[];
12 for(var i=0;i<arr.length-1;i++){//比较的次数是length-1
13 for(var j=0;j<arr.length-1-i;j++){
14 if(arr[j]>arr[j+1]){
15 var temp;
16 temp=arr[j];
17 arr[j]=arr[j+1];
18 arr[j+1]=temp;
19 }
20 }
21
22 }
23 alert(arr);
24
25 </script>
26 </body>
27 </html>