[英]number sorting function python not working (selection sort)
nums = [554, 565, 367, 69, 869, 965, 506, 136, 913, 463, 987, 315, 967, 35]
print(nums)
y=0
x=0
min=nums[x]
while y<len(nums):
while x<len(nums):
if min>nums[x]:
c=x
min=nums[c]
x=x+1
x=0
tmp=nums[y]
nums[0]=min
y+=1
min=tmp
print(nums)
我很困惑,為什么這段代碼沒有將數字從最低到最高排序。 我應該做選擇排序
將x=0
更改為x=y+1
。 這是一種選擇排序,您可以檢查一下以尋求幫助。
編輯:將算法鏈接更改為選擇排序。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.