MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / Simple

Function Simple

sort/simplesort.go:16–26  ·  view source on GitHub ↗
(arr []T)

Source from the content-addressed store, hash-verified

14import "github.com/TheAlgorithms/Go/constraints"
15
16func Simple[T constraints.Ordered](arr []T) []T {
17 for i := 0; i < len(arr); i++ {
18 for j := 0; j < len(arr); j++ {
19 if arr[i] < arr[j] {
20 // swap arr[i] and arr[j]
21 arr[i], arr[j] = arr[j], arr[i]
22 }
23 }
24 }
25 return arr
26}
27
28// ImprovedSimple is a improve SimpleSort by skipping an unnecessary comparison of the first and last.
29// This improved version is more similar to implementation of insertion sort

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected