Is there a queue implementation?

后端 未结 14 1173
时光取名叫无心
时光取名叫无心 2020-12-23 02:14

Can anyone suggest Go container for simple and fast FIF/queue, Go has 3 different containers: heap, list and vector. Which one is more

14条回答
  •  别那么骄傲
    2020-12-23 03:03

    To expand on the implementation side, Moraes proposes in his gist some struct from queue and stack:

    // Stack is a basic LIFO stack that resizes as needed.
    type Stack struct {
        nodes   []*Node
        count   int
    }
    // Queue is a basic FIFO queue based on a circular list that resizes as needed.
    type Queue struct {
        nodes   []*Node
        head    int
        tail    int
        count   int
    }
    

    You can see it in action in this playground example.

提交回复
热议问题