Commit aad7fbfe by BellCodeEditor

save project

parent 92449b0c
Showing with 28 additions and 2 deletions
import time
'''
begin_time=time.time()
list1 = [] list1 = []
for a in range(0, 1000): for a in range(0, 1000):
for b in range(0, 1000): for b in range(0, 1000):
list1.insert(0, 0) list1.append(0)
\ No newline at end of file end_time=time.time()
print(end_time-begin_time)
'''
#冒泡排序的实现原理
def b_l(l):
n = len(l)
#i表示第几轮
for i in range(0,n-1):
#j表示列表的下标
for j in range(0,n-1):
#比大小
if l[j] > l[j+1]:
l[j],l[j+1] = l[j+1],l[j]
num_list=[]
n=int(input("数字个数:"))
for i in range(n):
num=int(input("请输入第"+str(i+1)+"个数"))
num_list.append(num)
for i in range(n-1):
for j in range(n-1-i):
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)
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