วันเสาร์ที่ 31 ตุลาคม พ.ศ. 2558

Lab 7 - (Class) Insertion Sort Planning

def sort_insertion(my_list):
    i = 1
    while i < len(my_list):

        value_current = my_list[i]
        pos = i

        while((pos > 0) and (my_list[pos-1] > value_current)):
            my_list[pos] = my_list[pos-1]
            pos = pos-1
           
        if (pos != i):
            my_list[pos] = value_current
        i = i + 1
       
    return my_list
   

def setup():
   
    my_list = [15,26,28,17,77,31,44,55,20]
    print(my_list)
    print(sort_insertion(my_list))
   
setup()

ไม่มีความคิดเห็น:

แสดงความคิดเห็น