Created
January 26, 2023 13:46
-
-
Save didil/9a32566308a467fe4dd1c0f5ac5b831f to your computer and use it in GitHub Desktop.
go iteration sort generics any
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func InsertSortAny[T any](items []T) { | |
for i := 1; i < len(items); i++ { | |
// loop through subslices | |
for j := i; j > 0; j-- { | |
if items[j] < items[j-1] { | |
// swap elements if not ordered | |
items[j], items[j-1] = items[j-1], items[j] | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment