github.com/keysonZZZ/kmg@v0.0.0-20151121023212-05317bfd7d39/kmgSort/IntLessCallbackSort.go (about)

     1  package kmgSort
     2  
     3  import "sort"
     4  
     5  type IntLessCallbackSortT struct {
     6  	Data     []int
     7  	LessFunc func(a int, b int) bool
     8  }
     9  
    10  func (s *IntLessCallbackSortT) Len() int {
    11  	return len(s.Data)
    12  }
    13  
    14  func (s *IntLessCallbackSortT) Less(i, j int) bool {
    15  	return s.LessFunc(i, j)
    16  }
    17  
    18  func (s *IntLessCallbackSortT) Swap(i, j int) {
    19  	s.Data[i], s.Data[j] = s.Data[j], s.Data[i]
    20  }
    21  
    22  func (s *IntLessCallbackSortT) Sort() {
    23  	sort.Sort(s)
    24  }
    25  
    26  func IntLessCallbackSort(Data []int, LessFunc func(a int, b int) bool) {
    27  	sort.Sort(&IntLessCallbackSortT{Data: Data, LessFunc: LessFunc})
    28  }