Program Insertion Sort berikut ini saya tulisb dalam bahasa Python, sesuai dengan pseudocode dari buku “Introduction to Algorithms, Thomas H. Cormen” halaman 18.
Programnya sebagai berikut (saya jalankan di python 3.5.1) :
A=[5,2,4,6,1,3]
print(“Data sebelum di sortir :”)
for j in range(0,len(A)):
print(A[j],” “, end=”)
print()
for j in range(1, len(A)):
key=A[j]
i=j-1
while i>=0 and A[i] >key :
A[i+1]=A[i]
i=i-1
A[i+1]=key
print(“Data setelah di sortir :”)
for j in range(0,len(A)):
print(A[j],” “, end=”)
Program diatas menyortir list A secara Ascending. Untuk menyortir secara Descending, cukup mengubah baris :
while i>=0 and A[i] >key :
menjadi :
while i>=0 and A[i] <key :
http://staryue.com.tw/home.php?mod=space&uid=127892&do=profile&from=space
balance of nature
Mammie
balance of nature
http://www.youthnetradio.org/tmit/forum/home.php?mod=space&uid=392665&do=profile
https://pica7.tistory.com/238
https://mintfin.tistory.com/entry/EAB095EBA689EC8B9C-EAB8B4EAB889EC839DED999CEC9588ECA095ECA780EC9B90EAB888
Hi there, constantly i used to check web site posts here in the early
hours make money in internet the
dawn, since i like to learn more and more.
https://honeytipit.tistory.com/manage
???
??????????