Add insertion sort with less loops

This commit is contained in:
2023-10-22 19:37:54 +02:00
parent 1d68733dd8
commit 455d14ce69
2 changed files with 16 additions and 0 deletions

View File

@@ -35,4 +35,18 @@ func InsertionSort(list []int) []int {
}
return list
}
func TheOtherInsertionSort(list []int) []int {
for round := 1; round < len(list); round++ {
element_to_insert := list[round]
pos := round
for pos > 0 && element_to_insert < list[pos-1] {
list[pos] = list[pos-1]
pos--
}
list[pos] = element_to_insert
}
return list
}