Checkmark on Circle.png

Gnomesort/Python

Aus KGS-Wiki
< Gnomesort
Version vom 27. September 2024, 06:44 Uhr von Sn (Diskussion | Beiträge) (Die Seite wurde neu angelegt: „<syntaxhighlight lang="python" line> A = [19,84,650,13,47,65,10,6,50,16,58,70,56,10] n = len(A) i = 0 while not i == n-1: if A[i] <= A[i+1]: i = i + 1 else: a1 = A[i] a2 = A[i+1] A[i] = a2 A[i+1] = a1 if i > 0: i = i - 1 print(A) </syntaxhighlight>“)
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
A = [19,84,650,13,47,65,10,6,50,16,58,70,56,10]

n = len(A)
i = 0
while not i == n-1:
    if A[i] <= A[i+1]:
        i = i + 1
    else:
        a1 = A[i]
        a2 = A[i+1]
        A[i] = a2
        A[i+1] = a1
        if i > 0:
            i = i - 1
            
print(A)