#先用遍历实现排序,然后取两头的就是最大最小值了。可能是我太笨,思考的难受
def findMinAndMax(L):
if L==[]:
return (None,None)
for x in L[:]:
for i in L[:]:
if i>x and L.index(i)<L.index(x):
L.insert(L.index(x)+1,i)
L.pop(L.index(i))
elif i<x and L.index(i)>L.index(x):
L.insert(L.index(i)+1,x)
L.pop(L.index(x))
return (L[0], L[-1])
Sign in to make a reply
南丁叔叔
#先用遍历实现排序,然后取两头的就是最大最小值了。可能是我太笨,思考的难受
def findMinAndMax(L):
if L==[]:
return (None,None)
for x in L[:]:
for i in L[:]:
if i>x and L.index(i)<L.index(x):
L.insert(L.index(x)+1,i)
L.pop(L.index(i))
elif i<x and L.index(i)>L.index(x):
L.insert(L.index(i)+1,x)
L.pop(L.index(x))
return (L[0], L[-1])