💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
![](https://img.kancloud.cn/30/8d/308d9fed41a65b9693e9cf2b14dfa0b3_1263x486.png) ![](https://img.kancloud.cn/db/4d/db4df0a01233f073450fc5ba3d586691_993x163.png) ![](https://img.kancloud.cn/9b/0f/9b0f9e83125887f90be4aeeb6c00fa5c_711x624.png) ``` function bubble( ary){ let temp=null; //外层循环I控制比较的轮数 for(let i=0;i<ary.length-1;i++){ //里层循环控制每-轮比较的次数 for(let j=0;j<ary.length-1-i;j++){ if(ary[j]>ary[j+1]){ // 当前项大于后一项 temp=ary[j]; ary[j]=ary[j+1] ; ary [j+1] =temp; } } } return ary ; } let ary = [12,8,24,16,1];ary=bubble(ary); console.log(ary); ```