Skip to content

Commit

Permalink
Merge pull request #49 from BEAST-PRINCE/main
Browse files Browse the repository at this point in the history
Python solution for Insertion Sort
  • Loading branch information
lilmistake authored Oct 20, 2023
2 parents ae7cc0f + 52dfad9 commit ef65c80
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
25 changes: 25 additions & 0 deletions DSA_Codesheet/Python/insertion_Sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# The following function performs insertion sort in ascending order.
# The datatype used is a list(array of numbers).


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

return arr



arr = input("Enter a list of numbers: ").split(" ")

arr = [int(i) for i in arr]

sorted_arr = insertion_sort(arr)

for i in sorted_arr:
print(i,end=' ')
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ Distributed under the MIT License. See `LICENSE` for more information.
<table>
<tr>
<td align="center">
<a href="https://github.com/lilmistake">
<img src="https://avatars.githubusercontent.com/u/61899816?v=4" width="100;" alt="lilmistake"/>
<a href="https://github.com/BEAST-PRINCE">
<img src="https://avatars.githubusercontent.com/u/98230743?v=4" width="100;" alt="BEAST-PRINCE"/>
<br />
<sub><b>Rohit</b></sub>
<sub><b>DIVYANSHU PRINCE</b></sub>
</a>
</td>
<td align="center">
Expand All @@ -74,6 +74,13 @@ Distributed under the MIT License. See `LICENSE` for more information.
<sub><b>Chitresh Gyanani</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/lilmistake">
<img src="https://avatars.githubusercontent.com/u/61899816?v=4" width="100;" alt="lilmistake"/>
<br />
<sub><b>Rohit</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/yanurag1414">
<img src="https://avatars.githubusercontent.com/u/121807496?v=4" width="100;" alt="yanurag1414"/>
Expand Down

0 comments on commit ef65c80

Please sign in to comment.