‘‘‘ 选择排序:选择最小的,以此类推 ‘‘‘ import random import cProfile def select_Sort(nums): for i in range(len(nums)-1): for j in range(i+1,len(nums)): if nums[i] > nums[j]: # max = nums[i] # nums[i] = nums[j] # nums[j] = max #python有更好的写法 nums[i],nums[j] = nums[j],nums[i] return nums nums = [random.randint(0,10000) for i in range(10000)] print(select_Sort(nums)) cProfile.run(‘select_Sort(nums)‘)
运行结果:
排序:略
运行时间:3.339秒(稍微低于冒泡排序)
原文地址:https://www.cnblogs.com/shuimohei/p/10381245.html
时间: 2024-10-10 09:57:03