Insertion Sort in Python
arr = [5,4,3,2,1]
def insertion_sort(arr,N):
for passed in range(1,N):
temp = arr[passed]
i = passed-1
while (temp < arr[i] and (i>=0)):
arr[i+1] = arr[i]
i = i-1
arr[i+1] = temp
#pemangilan fungsi
insertion_sort(arr,5)
for j in range(0,5):
print(arr[j])
Komentar
Posting Komentar