Contoh Selection sort dalam bahasa python untuk Dasprog ITB
arr = [5,4,3,2,1]
def selectionsort(arr,N):
for passed in range(0,N-1):
minindex = passed
for j in range(passed+1,N):
if(arr[minindex] > arr[j]):
minindex = j
tukar = arr[passed]
arr[passed] = arr[minindex]
arr[minindex] = tukar
#pemangilan fungsi
selectionsort(arr,5)
for j in range(0,5):
print(arr[j])
Komentar
Posting Komentar