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() |
วันจันทร์ที่ 19 ตุลาคม พ.ศ. 2558
Lab06 : insertion sort
สมัครสมาชิก:
ส่งความคิดเห็น (Atom)
commit เพิ่มเติม : เพื่ม userstory, bookmark
>> add userstory ทำการเพิ่ม userstory ใน functional tests >> add bookmark for user เพิ่มระบบ Bookmark โดยการสร้าง model ขึ...
-
1 2 3 4 5 6 7 8 9 def setup (): print (d2b( 8 )) def d2b (num): x = "" while num > 0 : x = str ( int (n...
-
1 2 3 4 5 6 7 8 9 10 11 12 13 def test_layout_and_styling ( self ): # Edith goes to the home page self . brow...
-
การใช้ template inheritence คือการสืบทอดเทมเพลต เพื่อให้ไม่ต้องเขียนโค้ดหน้าเว็บๆซ้ำๆ เราจะมีหน้าหลักอันเดียว (base.html or parent) ภายในนั...
ไม่มีความคิดเห็น:
แสดงความคิดเห็น