Files
Go-tool/SourceAnalysisAndTool/jdkContainer/testContainer/HeapTool.go
T
2020-12-16 11:52:50 +08:00

37 lines
596 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* @Author : huangzj
* @Time : 2020/12/2 15:39
* @Description
*/
package testContainer
type Person struct {
Name string //名字
Age int //年龄
Money float64 //身价
}
type heapTool []*Person
func (h *heapTool) Less(i, j int) bool {
return (*h)[i].Age < (*h)[j].Age
}
func (h *heapTool) Swap(i, j int) {
(*h)[i], (*h)[j] = (*h)[j], (*h)[i]
}
func (h *heapTool) Len() int {
return len(*h)
}
func (h *heapTool) Pop() (v interface{}) {
*h, v = (*h)[:h.Len()-1], (*h)[h.Len()-1]
return
}
func (h *heapTool) Push(v interface{}) {
*h = append(*h, v.(*Person))
}