<div class="codetitle"> <span><a style="CURSOR: pointer" data="5379" class="copybut" id="copybut5379" onclick="doCopy('code5379')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code5379"> <br><script type="text/javascript"> <BR>var R1=[5,2,10,4,90,88,65,62]; <BR>var R2=[5,2,10,4,90,88,65,62]; <BR>function BubbleSort1(){ <BR>var n=R1.length; <BR>for(var i=0;i<n-1;i++){ <BR>var flag=false; <BR>for(var j=0;j<n-i;j++){ <BR>var temp; <BR>if(R1[j]<R1[j+1]){ <BR>temp=R1[j+1]; <BR>R1[j+1]=R1[j]; <BR>R1[j]=temp; <BR>} <BR>flag=true; <BR>} <BR>if(!flag) return; <BR>} <BR>} <BR>BubbleSort1(); <BR>document.write(R1.join(",")+"<br/>"); <BR>function BubbleSort2() <BR>{ <BR>var n=R2.length; <BR>for(var i=0;i<n-1;i++) <BR>{ <BR>var flag=false; <BR>for(var j=0;j<n-i;j++) <BR>{ <BR>var temp; <BR>if(R2[j]>R2[j+1]) <BR>{ <BR>temp=R2[j]; <BR>R2[j]=R2[j+1]; <BR>R2[j+1]=temp; <BR>} <BR>flag=true; <BR>} <BR>if(!flag) return; <BR>} <BR>} <br><br>BubbleSort2(); <BR>document.write(R2.join(",")) <br><br></script> <br> </div>