冒泡排序(参考Discrete Mathematics and Its Application一书中的伪码),,[Python]代码to


[Python]代码

tosort = [2, 3, 4, 1, 9, 10, 8, 7, 19, 7]for i in range(len(tosort)):   for j in range(len(tosort)-i-1):      if tosort[j]>tosort[j+1]:         tosort[j+1], tosort[j] = tosort[j], tosort[j+1]print tosort

[Python]代码

for i in range(len(tosort)):   for j in range(1, len(tosort)-i):      if tosort[j-1]>tosort[j]:         tosort[j-1], tosort[j] = tosort[j], tosort[j-1]print tosort

评论关闭