Skip to content

Commit

Permalink
Create insertionsort.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ashutosh das authored and ashutosh das committed Oct 19, 2024
1 parent 6beac31 commit 840defe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Binary file added Python/.DS_Store
Binary file not shown.
19 changes: 19 additions & 0 deletions Python/insertionsort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
def insertion_sort(arr):
for i in range(1, len(arr)):
key = arr[i]
j = i - 1
while j >= 0 and key < arr[j]:
arr[j + 1] = arr[j]
j -= 1
arr[j + 1] = key

def main():
user_input = input("Enter numbers separated by spaces: ")
arr = list(map(int, user_input.split()))

print("Original array:", arr)
insertion_sort(arr)
print("Sorted array:", arr)

if __name__ == "__main__":
main()

0 comments on commit 840defe

Please sign in to comment.