#利用嵌套for循环 完成冒泡排序
#拓展:冒泡算法是什么?
L=[4,9,10,5,111,3,244]
答案:
for i in range(0,len(L)-1):
for j in (i,len(L)-2):
if L[j]>L[j+1]:
L[j],L[j+1]=L[j+1],L[j]
print(L)
#利用嵌套for循环 完成冒泡排序
#拓展:冒泡算法是什么?
L=[4,9,10,5,111,3,244]
答案:
for i in range(0,len(L)-1):
for j in (i,len(L)-2):
if L[j]>L[j+1]:
L[j],L[j+1]=L[j+1],L[j]
print(L)
public static int[] maopao(int[] shuzu) {
for (int i = 0; i < shuzu.length; i++) {
for (int j = 0; j < shuzu.length - 1; j++) {
if (shuzu[j] > shuzu[j + 1]) {
int temp = shuzu[j];
shuzu[j] = shuzu[j + 1];
shuzu[j + 1] = temp;
}
}
}
return shuzu;
}
for i in range(len(L)):
for j in range(len(L)-1):
if L[j]>L[j+1]:
L[j],L[j+1]=L[j+1],L[j]
print(L)
欢迎来到testingpai.com!
注册 关于