package q5 import ( "sort" ) type sortImpl[T any] struct { data []*T lessCb func(*T, *T) bool } func (this *sortImpl[T]) Len() int { return len(this.data) } func (this *sortImpl[T]) Swap(i int, j int) { this.data[i], this.data[j] = this.data[j], this.data[i] } func (this *sortImpl[T]) Less(i int, j int) bool { return this.lessCb(this.data[i], this.data[j]) } func Sort[T any](data []*T, lessCb func(*T, *T) bool) { impl := new(sortImpl[T]) impl.data = data impl.lessCb = lessCb sort.Sort(impl) }