-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Insertion Sort Code using Python
- Loading branch information
1 parent
6e827aa
commit 255dd75
Showing
1 changed file
with
19 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Python program for implementation of Insertion Sort | ||
|
||
def insertionSort(arr): | ||
|
||
for i in range(1, len(arr)): | ||
|
||
key = arr[i] # Move elements of arr that are greater than key, to one position ahead of their current position | ||
j = i-1 | ||
while j >= 0 and key < arr[j] : | ||
arr[j + 1] = arr[j] | ||
j -= 1 | ||
arr[j + 1] = key | ||
|
||
print("Enter the array elements : ") | ||
arr = list(map(int,input().split())) | ||
insertionSort(arr) | ||
print ("\nSorted array is ",str(arr)) | ||
|
||
|