Created
September 23, 2015 11:26
-
-
Save rishi93/1c42cb1109000ea540fc to your computer and use it in GitHub Desktop.
Insertion Sort
This file contains hidden or 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
| def insertionsort(arr): | |
| for i in range(1,len(arr)): | |
| val = arr[i] | |
| j = i - 1 | |
| while j >= 0 and arr[j]>val: | |
| arr[j+1] = arr[j] | |
| j -= 1 | |
| arr[j+1] = val | |
| print(arr) | |
| arr = [54,26,93,17,77,31,44,55,20] | |
| insertionsort(arr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment