March 2020
Intermediate to advanced
406 pages
8h 39m
English
A deque, or a double-ended queue, is a container that can be expanded. These expansions can occur in the front or the back of the container. Deques are often used when the top or the back of a queue needs to be referenced frequently. The following code block is a simple implementation of a deque:
package mainimport ( "fmt" "gopkg.in/karalabe/cookiejar.v1/collections/deque")func main() { d := deque.New() elements := []string{"foo", "bar", "baz"} for i := range elements { d.PushLeft(elements[i]) } fmt.Println(d.PopLeft()) // queue => ["foo", "bar"] fmt.Println(d.PopRight()) // queue => ["bar"] fmt.Println(d.PopLeft()) // queue => empty}
The deque package takes a slice of elements and pushes them onto the queue with the PushLeft function. ...
Read now
Unlock full access