ImprovedSimple is a improve SimpleSort by skipping an unnecessary comparison of the first and last. This improved version is more similar to implementation of insertion sort
(arr []T)
| 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 |
| 30 | func ImprovedSimple[T constraints.Ordered](arr []T) []T { |
| 31 | for i := 1; i < len(arr); i++ { |
| 32 | for j := 0; j < len(arr)-1; j++ { |
| 33 | if arr[i] < arr[j] { |
| 34 | // swap arr[i] and arr[j] |
| 35 | arr[i], arr[j] = arr[j], arr[i] |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | return arr |
| 40 | } |
nothing calls this directly
no outgoing calls
no test coverage detected