快速排序python实现
#--×--coding:utf-8-*-
def main():
nlist = []
while 1:
tmp = raw_input("Please input your element,end by -1")
if int(tmp ) == -1:
break
nlist.append(tmp)
InsertSort(nlist)
def InsertSort(nlist):
nlistSize = len(nlist)
for index in xrange(nlistSize - 1):
for currentindex in xrange(index, nlistSize - 1):
if nlist[currentindex] > nlist[currentindex + 1]:
nlist[currentindex] , nlist[currentindex + 1] = nlist[currentindex +1] > nlist[currentindex]
print "排序后的",nlist
if __name__ == "__main__":
main()

浙公网安备 33010602011771号