Commit bf79d634 by BellCodeEditor

auto save

parent 13a17170
list = [1,2,3,4,5,6]
for i in range(len(list)-1):
for j in range(len(list)-i-1):
if list[j] < list[j+1]:
list[j],list[j+1] = list[j+1],list[j]
print(list)
\ No newline at end of file
import time import time
start = time.time()#开始的时间
start_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(-1, 0) list1.insert(-1, 0)
end_time = time.time() #结束时间 end = time.time()#结束时间
result = end - start # #开始的时间-结束的时间 = 运行的时间
result = end_time - start_time print(result)
print('程序运行时间是',result) \ No newline at end of file
\ No newline at end of file
import time alist = [20, 17, 9, 13, 5, 6,1,2,5,5,4,56,656,65,65]
list1 = []
start_time = time.time() #冒泡排序
for a in range(0, 1000): for i in range(len(alist)-1):
for b in range(0, 1000): for j in range(len(alist)-1-i):
list1.insert(0,0) if alist[j] > alist[j+1]:
end_time = time.time() alist[j], alist[j+1] = alist[j+1], alist[j]
print('结束时间',end_time) print(alist)
result = end_time-start_time
print('总耗时',result)
\ No newline at end of file
import time
start = time.time()
print(start)
alist = [20,17,9,13,5,6,2,567]
for j in range(len(alist)-1):
for i in range(len(alist)-j-1):
if alist[i] > alist[i+1]:
alist[i],alist[i+1]=alist[i+1],alist[i]
result = start - time.time()
print(result)
\ No newline at end of file
alist = [20, 17, 9, 13, 5, 6]
for i in range(len(alist)-1): #i 比较几轮
for j in range(len(alist)-1-i): # j = 0 1 2 3 4 5 j索引
if alist[j]>alist[j+1]:
alist[j],alist[j+1] = alist[j+1],alist[j]
print(alist)
\ No newline at end of file
import time
start_time = time.time() #开始时间 1970年1月1日0时0分0秒 到现在的总秒数
list1 = []
for a in range(0, 1000):
for b in range(0, 1000):
list1.insert(-1, 0)
end_time = time.time() #结束时间 1970年1月1日0时0分0秒 到现在的总秒数
result = end_time - start_time #代码运行时间
print('代码运行时间是:',result)
alist = [20, 17, 9, 13, 5, 6] #5
for i in range(len(alist)-1):
for j in range(len(alist)-1-i): # 0 , 1 , 2, 3, 4, 5
if alist[j] > alist[j+1]:
alist[j],alist[j+1] = alist[j+1],alist[j]
print(alist)
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):
......
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