feat: Add Insertion sort

This commit is contained in:
2026-05-31 14:49:05 +05:30
parent f27f04ed1f
commit 9e613554b7
2 changed files with 26 additions and 1 deletions
+19
View File
@@ -0,0 +1,19 @@
package algo
import "fmt"
func InsertionSort(a []int, n int) {
fmt.Println("-- Insertion Sort --")
fmt.Printf("Input: %v\n", a)
for i := 1; i < n; i++ {
key := a[i]
j := i - 1
for ; j >= 0 && a[j] > key; j-- {
a[j+1] = a[j]
}
a[j+1] = key
}
fmt.Printf("Output: %v\n", a)
}