zoukankan      html  css  js  c++  java
  • golang container heap&sort

    go语言也自己的容器数据结构。主要有list、heap和ring

    package main
    
    import (
        "container/heap"
        "fmt"
        "sort"
        // "strconv"
    )
    
    
    type HeapInt []int
    
    func (h HeapInt) Len() int {
        return len(h)
    }
    
    func (h HeapInt) Less(i, j int) bool {
        return h[i] < h[j]
    }
    func (h HeapInt) Swap(i, j int) {
        h[i], h[j] = h[j], h[i]
    }
    
    func (h *HeapInt) Push(x interface{}) {
        *h = append(*h, x.(int))
    }
    func (h *HeapInt) Pop() interface{} {
        old := *h
        n := len(old)
        x := old[n-1]
        *h = old[0 : n-1]
        return x
    }
    
    func (h *HeapInt) Search(n Item,f func(Item)bool{})int {
        
    }
    
    func main() {
        slice := make(HeapInt, 0)
        heap.Init(&slice)
        for i := 0; i < 10; i++ {
            heap.Push(&slice, i*i)
        }
        for i := 0; i < 10; i++ {
            fmt.Println(slice[i])
        }
        bb := sort.SearchInts(slice, 23)
        fmt.Println(bb)
    }
  • 相关阅读:
    CSS filter属性
    css过渡的使用
    关于2D、3D的转换
    3D立体旋转
    css的规范命名
    html标签的简单总结
    css之简单动画
    几种动态的学习链接
    css之规范命名
    css
  • 原文地址:https://www.cnblogs.com/guhao123/p/4184949.html
Copyright © 2011-2022 走看看