Files
llgo/_demo/c/qsort/qsort.go

26 lines
323 B
Go
Raw Normal View History

2024-05-06 13:26:09 +08:00
package main
import (
"unsafe"
2025-04-03 15:52:18 +08:00
"github.com/goplus/lib/c"
2024-05-06 13:26:09 +08:00
)
func main() {
a := [...]int{100, 8, 23, 2, 7}
c.Qsort(c.Pointer(&a), 5, unsafe.Sizeof(0), func(a, b c.Pointer) c.Int {
return c.Int(*(*int)(a) - *(*int)(b))
})
for _, v := range a {
c.Printf(c.Str("%d\n"), v)
}
}
2024-05-06 22:31:33 +08:00
/* Expected output:
2
7
8
23
100
*/