Skip to content

Commit 0614f89

Browse files
authored
Merge pull request Aishanipach#14 from musaibbatghar/main
Insertion Sort Algorithm Implementation
2 parents d268791 + b3dbce6 commit 0614f89

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

Insertion_Sort.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
def insertionSort(arr):
3+
4+
for i in range(1, len(arr)):
5+
6+
key = arr[i]
7+
j = i-1
8+
while j >=0 and key < arr[j] :
9+
arr[j+1] = arr[j]
10+
j -= 1
11+
arr[j+1] = key
12+
13+
14+
arr = [12, 11, 13, 5, 6]
15+
insertionSort(arr)
16+
lst = []
17+
print("Sorted array is : ")
18+
for i in range(len(arr)):
19+
lst.append(arr[i])
20+
print(lst)
21+
22+

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ Feel free to add basic python scripts/programs that helped you learn python. I h
3333
16. [email response sender](https://github.com/arnavvgupta/email-response-sender) - [Arnav Gupta](https://github.com/arnavvgupta)
3434
17. [Quick Sort](https://github.com/varshaah2407/Beginners-Python-Projects/blob/main/quick_sort.py) - [Varshaah Shashidhar](https://github.com/varshaah2407)
3535
18. [aritmetic median, biggest number and lowest number](https://github.com/arnavvgupta/functionMaxMinMedian.py)
36-
36+
19. [Insertion Sort](https://github.com/musaibbatghar/Beginners-Python-Projects/blob/main/Insertion_Sort.py) - [Musaib Batghar](https://github.com/musaibbatghar)

0 commit comments

Comments
 (0)