From e6640b7f475109ceb177d5e083ecd5318c38f86a Mon Sep 17 00:00:00 2001 From: Bobertkiller Date: Tue, 25 Oct 2022 19:38:56 -0300 Subject: [PATCH] new algorithm soon to be more --- sort_algorithms.py | 11 +++++++++++ 1 file changed, 11 insertions(+) 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