From 28d28b817ea61e473760be780c0e03021d518072 Mon Sep 17 00:00:00 2001 From: marina <138340846+bt3gl-cryptographer@users.noreply.github.com> Date: Wed, 2 Aug 2023 20:54:05 -0700 Subject: [PATCH] Create insertion_sort.py --- sorting/insertion_sort.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 sorting/insertion_sort.py diff --git a/sorting/insertion_sort.py b/sorting/insertion_sort.py new file mode 100644 index 0000000..861a804 --- /dev/null +++ b/sorting/insertion_sort.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# author: bt3gl + +def insertion_sort(lst): + + for i in range(1, len(lst)): + current_index = i + + while current_index > 0 and lst[current_index - 1] > lst[current_index]: + + lst[current_index], lst[current_index - 1] = lst[current_index - 1], lst[current_index] + current_index -= 1