插入排序:
a = [6,4,0,7,1,5,9,8]
for j in range(1,len(a)):
key = a[j]
i = j - 1;
while( i >= 0 and a[i] > key):
a[i + 1] = a[i];
i= i - 1;
a[i+1] = key;
print(a)
选择排序:
a = [6,4,0,7,1,5,9,8]
for j in range(0,len(a)-1):
key = j
i = j + 1;
while( i <len(a) ):
if(a[i] < a[key]):
key = i;
i= i + 1;
temp = a[j];
a[j] = a[key];
a[key] = temp;
print(a)