24 lines
567 B
Python
24 lines
567 B
Python
|
#!/usr/bin/env python3
|
||
|
|
||
|
import sys
|
||
|
|
||
|
def insertionsort(A):
|
||
|
# start with the first and the second
|
||
|
# insert the next element in the right place in the first elements
|
||
|
# continue until the array is done
|
||
|
for j in range(1,len(A)):
|
||
|
print(A)
|
||
|
print(A)
|
||
|
i = j - 1
|
||
|
tomove = A[j]
|
||
|
while i >= 0 and tomove < A[i]:
|
||
|
if A[i] > A[i+1]:
|
||
|
# Swap A[i] and A[j]
|
||
|
A[i+1], A[i] = A[i], A[i+1]
|
||
|
i = i - 1
|
||
|
return A
|
||
|
|
||
|
|
||
|
args = [int(x) for x in sys.argv[1:]]
|
||
|
print(insertionsort(args))
|