Golang-container包

container 包含 List,Heap, Ring

List 双向链表

// Element is an element of a linked list.
type Element struct {
    // Next and previous pointers in the doubly-linked list of elements.
    // To simplify the implementation, internally a list l is implemented
    // as a ring, such that &l.root is both the next element of the last
    // list element (l.Back()) and the previous element of the first list
    // element (l.Front()).
    next, prev *Element

    // The list to which this element belongs.
    list *List

    // The value stored with this element.
    Value interface{}
}

Heap 堆

可以用来实现大顶堆,小顶堆

代码实现如下

Ring 环

双向循环链表

参考

Last updated

Was this helpful?