冒泡排序:
class mysort(object):
def bubble_sort(self, l):
source = l[:]
for i in range(len(l)):
for j in range(i):
if l[i] < l[j]:
l[i], l[j] = l[j], l[i]
print "bubble_sort: source= {0}; result= {1}".format(source, l)
if __name__ == "__main__":
my = mysort()
my.bubble_sort([3,2,4,7,0,1])
运行结果:
bubble_sort: source= [3, 2, 4, 7, 0, 1]; result= [0, 1, 2, 3, 4, 7]
测试开发岗位的话,这题被考的概率特别大。