1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-23 13:52:26 +08:00

Compare commits

...

3 Commits

Author SHA1 Message Date
dudaodong
0bc7b83e59 Merge branch 'main' into v2 2023-12-21 10:03:35 +08:00
duckjiangwei
6225418074 improvement:optimize bubble sort (#152) 2023-12-21 10:02:23 +08:00
dudaodong
ddd265de78 fix: fix comment error 2023-12-19 15:36:07 +08:00
2 changed files with 7 additions and 2 deletions

View File

@@ -9,12 +9,17 @@ import "github.com/duke-git/lancet/v2/constraints"
// Play: https://go.dev/play/p/GNdv7Jg2Taj
func BubbleSort[T any](slice []T, comparator constraints.Comparator) {
for i := 0; i < len(slice); i++ {
breakTag := false
for j := 0; j < len(slice)-1-i; j++ {
isCurrGreatThanNext := comparator.Compare(slice[j], slice[j+1]) == 1
if isCurrGreatThanNext {
swap(slice, j, j+1)
breakTag = true
}
}
if !breakTag {
break
}
}
}

View File

@@ -330,10 +330,10 @@ func Cos(radian float64, precision ...int) float64 {
return TruncRound(radian, 3)
}
// Cos returns the sine of the radian argument.
// Sin returns the sine of the radian argument.
// Play: https://go.dev/play/p/TWMQlMywDsP
func Sin(radian float64, precision ...int) float64 {
return Cos((math.Pi / 2) - radian)
return Cos((math.Pi/2)-radian, precision...)
}
// Log returns the logarithm of base n.