#排序 Programming World Game Rules # values found according to the index # value can be swapped for size # value can be exchanged position # bubble sort # In contrast, if an element is larger than the right, swap position Arr=[3,4,8,9,10,6,5,7]length=len (arr) for I In range (length-1):p rint ' * ' *20print IFOR J in Range (length-i-1): If arr[j]>arr[j+1]: arr[j],arr[j+1]=arr[j+1],arr[j ] print ' list is%s '% (arr) Print arr
#coding =utf-8# Insert Sort # Insert Sort (insertion sort) The algorithm description is a simple and intuitive sorting algorithm. It works by constructing an ordered sequence, for unsorted data, from a backward forward scan in a sorted sequence, to find the appropriate location and insert an array = [3,1,4,2,5,7,6]length = Len (array) for I in Range (length-1): for J in Range (I+1,length): If ARRAY[I]>ARRAY[J]: Array[i],array[j]=array[j],array[i]print array
This article from "Do not abandon!" Do not give up "blog, declined reprint!"
Python Learning Second Order