From 724fdc4d86148fa00a6cb4b6597778a2455b654f Mon Sep 17 00:00:00 2001 From: nolancon Date: Fri, 1 Oct 2021 21:04:32 +0000 Subject: [PATCH] insertion sort --- Algorithms/insertion_sort.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Algorithms/insertion_sort.go diff --git a/Algorithms/insertion_sort.go b/Algorithms/insertion_sort.go new file mode 100644 index 0000000..8b8c2c5 --- /dev/null +++ b/Algorithms/insertion_sort.go @@ -0,0 +1,12 @@ +package main + +func insertionSort(list []int) []int { + for i := 0; i < len(list); i++ { + for j := i + 1; j < len(list); j++ { + if list[j] < list[i] { + list[i], list[j] = list[j], list[i] + } + } + } + return list +}