from random import *
maxn = 100000 + 10
a = [-1,9,1,2,3,8,16,85,24,984,35198,168,325,35384,84,61,684]
#从id = 0开始共计17个元素
def Bubble_Sort(L, R):#冒泡排序
for i in range(L, R + 1):
for j in range(R - 1, L - 1, -1):
if a[j] > a[j + 1]:
tmp = a[j]
a[j] = a[j + 1]
a[j + 1] = tmp
#Bubble_Sort(0, 16)
#print(a)
#Accepted!
def Insert_Sort(L, R):#插入排序
for i in range(L, R + 1):
for j in range(i, L, -1):
if a[j] < a[j - 1]:
tmp = a[j]
a[j] = a[j - 1]
a[j - 1] = tmp
else:
break
#Insert_Sort(0, 16)
#print(a)
#Accepted!
def Selection_Sort(L, R):#选择排序
for i in range(L, R + 1):
min_number = a[i]
min_position = i
for j in range(i + 1, R + 1):
if min_number > a[j]:
min_number = a[j]
min_position = j
a[min_position] = a[i]
a[i] = min_number
#Selection_Sort(0, 16)
#print(a)
#Accepted!
Python 基本排序算法基础实战【O(n^2):冒泡排序、插入排序、选择排序】
最新推荐文章于 2021-10-03 00:41:41 发布