python- sorting algorithm

Sort exchange

  Exchange sort bubble sort and quick sort have

Bubble Sort

  Bubble sort is the time to find the maximum (minimum) element in the set top or bottom, this is the easiest of sorting algorithms

print ( "unsorted until:", collection) # + can not be written (str not be prompted for the type of data should be rewritten so) 
    # ascending 

    TEMP = Collection [0] 
    length = len (Collection) 
    for S in Range (Length- . 1): 
        for I in Range (length-. 1-S): 
            iF Collection [I]> Collection [I +. 1]: # former big need to change positions, and need to determine whether he is the largest 
                TEMP = Collection [I] 
                Collection [I] = Collection [I +. 1] 
                Collection [I +. 1] = TEMP 
            the else: 
                Continue 
    ( "after the wheel:" "sorting", s + 1,, collection ) print #print () representing a good time ah

  

Guess you like

Origin www.cnblogs.com/Gaoqiking/p/10965769.html