Skip to content

Commit

Permalink
Merge branch 'sorting'
Browse files Browse the repository at this point in the history
  • Loading branch information
liontiger23 committed Oct 4, 2024
2 parents 23bff0f + dae51ad commit f6c1e11
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
arr = [40, 4, 20, 10, 30, 6, 10]

# insertion sort:
for i in range(1, len(arr)):
a_i = arr[i]
j = i - 1
while j >= 0:
print("comparing {} and {}".format(arr[j], arr[i]))
if arr[j] > a_i:
arr[j + 1] = arr[j]
else:
break
j -= 1
arr[j + 1] = a_i

print(arr)

0 comments on commit f6c1e11

Please sign in to comment.