python看了好多遍,没怎么coding,这里简单写个
1 #!/usr/bin/python 2 def printSide(qsort): 3 def inner_print(ls,begin,end): 4 print("(%d,%d)"%(begin,end)) 5 qsort(ls,begin,end) 6 return inner_print 7 8 @printSide 9 def qsort(ls,begin,end): 10 if begin>=end: 11 return 12 tmp = ls[begin] 13 pos = begin 14 for mov in range(begin+1, end+1): 15 if ls[mov]<tmp: 16 pos += 1 17 ls[pos],ls[mov] = ls[mov],ls[pos] 18 ls[begin],ls[pos] = ls[pos],ls[begin] 19 if pos - 1 > begin: 20 qsort(ls,begin,pos-1) 21 if pos + 1 < end: 22 qsort(ls,pos+1,end) 23 24 def myGenerator(num): 25 for i in range(0,num): 26 yield i 27 28 if __name__ == "__main__": 29 ls = [] 30 for i in myGenerator(10): 31 ls.append(int(input("Please input number: "))) 32 print(ls) 33 qsort(ls,0,len(ls)-1) 34 print(ls)