Commit 7190ed6a by BellCodeEditor

auto save

parent 2ffe1ce6
Showing with 37 additions and 17 deletions
a = 3
b = 2
a,b = b,a
print(a,b)
\ No newline at end of file
a=3
b =2
# a,b = b,a
# print(a,b)
c= 0
c = a #3
a = b #2
b = c #3
print(a,b)
#输入n个正整数将其存储到一个列表中,然后从小到大升序排列
#第一步存储
#第一步存储
num_list = []
n = int(input("请输入数字个数:"))
n = int(input("请输入需要的数字个数:"))
for i in range(n):
num = int(input("请输入"+str(i+1)+"个数字:"))
num = int(input("输入第"+str(i+1)+"个数字"))
num_list.append(num)
print(num_list)
#第二步:从小到大冒泡排序
#表示第几轮
#第二步:冒泡排序
for i in range(n-1):
#表示索引位置
for j in range(n-1-i):
for j in range(n-1):
if num_list[j]>num_list[j+1]:
num_list[j],num_list[j+1] = num_list[j+1],num_list[j]
print(num_list)
......@@ -27,3 +25,10 @@ for i in range(n-1):
......@@ -15,16 +15,17 @@
#冒泡排序的实现原理
def maopao(list):
n = len(list)
#i表示当前第几轮
#i表示第几轮
for i in range(n-1):
#j表示列表的下标
for j in range(n-1-i):
#j表示索引位置对应的下标
for j in range(n-1):
#比大小
if list[j]>list[j+1]:
#换位置
#换位置
list[j],list[j+1] = list[j+1],list[j]
......@@ -37,3 +38,7 @@ def maopao(list):
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment