mirror of
https://github.com/duke-git/lancet.git
synced 2026-03-01 00:35:28 +08:00
Compare commits
3 Commits
80e48f06ca
...
0bc7b83e59
| Author | SHA1 | Date | |
|---|---|---|---|
| 0bc7b83e59 | |||
| 6225418074 | |||
| ddd265de78 |
@@ -9,12 +9,17 @@ import "github.com/duke-git/lancet/v2/constraints"
|
|||||||
// Play: https://go.dev/play/p/GNdv7Jg2Taj
|
// Play: https://go.dev/play/p/GNdv7Jg2Taj
|
||||||
func BubbleSort[T any](slice []T, comparator constraints.Comparator) {
|
func BubbleSort[T any](slice []T, comparator constraints.Comparator) {
|
||||||
for i := 0; i < len(slice); i++ {
|
for i := 0; i < len(slice); i++ {
|
||||||
|
breakTag := false
|
||||||
for j := 0; j < len(slice)-1-i; j++ {
|
for j := 0; j < len(slice)-1-i; j++ {
|
||||||
isCurrGreatThanNext := comparator.Compare(slice[j], slice[j+1]) == 1
|
isCurrGreatThanNext := comparator.Compare(slice[j], slice[j+1]) == 1
|
||||||
if isCurrGreatThanNext {
|
if isCurrGreatThanNext {
|
||||||
swap(slice, j, j+1)
|
swap(slice, j, j+1)
|
||||||
|
breakTag = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if !breakTag {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -330,10 +330,10 @@ func Cos(radian float64, precision ...int) float64 {
|
|||||||
return TruncRound(radian, 3)
|
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
|
// Play: https://go.dev/play/p/TWMQlMywDsP
|
||||||
func Sin(radian float64, precision ...int) float64 {
|
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.
|
// Log returns the logarithm of base n.
|
||||||
|
|||||||
Reference in New Issue
Block a user