วันจันทร์ที่ 19 ตุลาคม พ.ศ. 2558

Lab06 : insertion sort

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
def setup():
    name=["John","Henry","Michael","Morgan","Hestia","Lux","Lulu","EX","L"]
    id=[1,2,3,4,5,6,7,8,9]
    age=[17,16,19,15,20,12,17,13,14]
    weight=[70,90,65,55,50,78,56,57,67]
    height=[156,170,175,172,173,174,159,160,165]
    insertion_sort(age,name,id,weight,height) #sort by age
    i=0
    while i<len(age):
        print(" [id",id[i],"][ Name",name[i],"][ age",age[i],"][ weight",weight[i],"][ height",height[i],"]")
        i+=1
def insertion_sort(a,b,c,d,e): # sort by a
    i=1
    j=0
    while i<len(a):
        j=i
        while j>0 and a[j]<a[j-1]:
            swap(j,j-1,a)
            swap(j,j-1,b)
            swap(j,j-1,c)
            swap(j,j-1,d)
            swap(j,j-1,e)
            j-=1
        i+=1
def swap(i,k,a): # i,k are indices a=array
    temp=a[i]
    a[i]=a[k]
    a[k]=temp
setup()

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

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

commit เพิ่มเติม : เพื่ม userstory, bookmark

>>  add userstory ทำการเพิ่ม userstory ใน functional tests >>  add bookmark for user เพิ่มระบบ Bookmark โดยการสร้าง model ขึ...