diff --git a/Algorithms/insertion_sort.go b/Algorithms/insertion_sort.go new file mode 100644 index 0000000..54ebbba --- /dev/null +++ b/Algorithms/insertion_sort.go @@ -0,0 +1,20 @@ +package main + +import "fmt" + +func insertioSort(arr []int) []int { + for i := 1; i < len(arr); i++ { + j := i + for j > 0 { + if arr[j-1] > arr[j] { + arr[j-1], arr[j] = arr[j], arr[j-1] + } + j = j - 1 + } + } + return arr +} +func main() { + items := []int{45, 100, 1, 20, 31, 63, 70, 2, 9} + fmt.Println(insertioSort(items)) +}