diff --git a/sort_algorithms.py b/sort_algorithms.py index 977635a..8534e56 100644 --- a/sort_algorithms.py +++ b/sort_algorithms.py @@ -32,3 +32,14 @@ def selection(arr): print(selection(a)) #insertion sort +def insertion(arr): + for i in range(1,len(arr)): + x = arr[i] + j = i-1 + while j>= 0 and x < arr[j]: + arr[j + 1] = arr[j] + j -= 1 + arr[j + 1] = x + return arr + +print(insertion(a)) \ No newline at end of file