python中用二分法的递归方式求n个元素的最大值和最小值,传递参数时不用分片,急求
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励20(财富值+成长值)
展开全部
def sort(lst):
shortHelper(lst,0,len(lst)-1)
def shortHelper(lst,low,high):
if low < high:
indexOfMin = low
min = lst[low]
for i in range(low+1,high+1):
if lst[i] < min:
min = lst[i]
indexOfMin = i
lst[indexOfMin] = lst[low]
lst[low] = min
shortHelper(lst,low+1,high)
if __name__ == '__main__':
lst = [3,4,5,1,2,6,2]
sort(lst)
print (lst)
print (lst[0])
print (lst[-1])
shortHelper(lst,0,len(lst)-1)
def shortHelper(lst,low,high):
if low < high:
indexOfMin = low
min = lst[low]
for i in range(low+1,high+1):
if lst[i] < min:
min = lst[i]
indexOfMin = i
lst[indexOfMin] = lst[low]
lst[low] = min
shortHelper(lst,low+1,high)
if __name__ == '__main__':
lst = [3,4,5,1,2,6,2]
sort(lst)
print (lst)
print (lst[0])
print (lst[-1])
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询