Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
507 B
0
Indexable
Never
numbers = [5, 7, 8, 3, 9]
def insertionSort(numbers):
    for first in range(1, len(numbers)):
        #gdzie wstawić liczbę
        i = first - 1
        index = 0
        while i >= 0:
            if numbers[i] < numbers[first]:
                index = i + 1
                break
            i -= 1
        temp = numbers[first]
        i = first
        while i > index:
            numbers[i] = numbers[i - 1]
            i -= 1
        numbers[index] = temp

insertionSort(numbers)
print(numbers)