分类: Python/Ruby
2009-05-25 18:05:36
转自
# -*- coding: utf-8 -*-
def charu(list):
length = len(list)
for i in range(1,length):
temp = list[i]
j = i - 1
while list[j] > temp:
list[j+1] = list[j]
list[j] = temp
j = j - 1
if j < 0:
break
return list
def xuanze(list):
length = len(list)
for i in range(0,length):
k = i
for j in range(i+1,length):
if list[k] > list[j]:
k = j
if k != i:
temp = list[i]
list[i] = list[k]
list[k] = temp
return list
def maopao(list):
length = len(list)
if length <= 0:
return []
for i in range(0,length):
for j in range(length-1,i,-1):
if list[j] < list[j-1]:
temp = list[j]
list[j]=list[j-1]
list[j-1]=temp
return list
def kuaisu(ls):
return [] if ls == [] \
else kuaisu([y for y in ls[1:] if y < ls[0]]) + \
[ls[0]] + \
kuaisu([y for y in ls[1:] if y >= ls[0]])
list = [38,65,97,76,13,27,49]
print charu(list)
print xuanze(list)
print maopao(list)
print kuaisu(list)
基本只要稍微改改,就可以用~~我已经用了。。挺好用。