02. 选择排序 #46
utterances-bot
started this conversation in
Comments
Replies: 4 comments 1 reply
-
牛,就是感觉跟冒泡其实时间复杂度差不多,为啥不直接用冒泡呢。。。 |
Beta Was this translation helpful? Give feedback.
0 replies
-
冒泡排序每轮交换的次数比较多,而选择排序每轮只交换一次;在时间效率上,选择排序优于冒泡排序。 |
Beta Was this translation helpful? Give feedback.
1 reply
-
def sel(lst):
for i in range(len(lst)-1):
temp_min = i
for j in range(i+1,len(lst)):
if lst[j] < lst[i]:
temp_min = j
if i != temp_min:
temp = lst[i]
lst[i] = lst[j]
lst[j] = temp
return lst
lst = [5,2,3,6,1,4]
print(sel(lst)) |
Beta Was this translation helpful? Give feedback.
0 replies
-
这篇文章动画演示更好理解:https://mp.weixin.qq.com/s/iJvPegXpBRI6dkzLWEE6dA |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
02.选择排序 | 算法通关手册
选择排序 # 1. 选择排序算法思想 # 选择排序(Selection Sort)基本思想: 将序列分为两部分:前边 i - 1 个元素为已排序部分,后边 n - i + 1
https://algo.itcharge.cn/01.Array/02.Array-Sort/02.Array-Selection-Sort/
Beta Was this translation helpful? Give feedback.
All reactions