March 2020
Intermediate to advanced
406 pages
8h 39m
English
Queues are containers that follow the FIFO queuing method, or first in first out. This means that we can add things to the container and pull them from the other end of the container. We can make the simplest form of a queue by appending and dequeueing from a slice, as shown in the following code:
package mainimport "fmt"func main() { var simpleQueue []string simpleQueue = append(simpleQueue, "Performance ") simpleQueue = append(simpleQueue, "Go") for len(simpleQueue) > 0 { fmt.Println(simpleQueue[0]) // First element simpleQueue = simpleQueue[1:] // Dequeue } fmt.Println(simpleQueue) //All items are dequeued so result should be []}
In our example, we append strings to our simpleQueue and then dequeue them by removing the first element ...
Read now
Unlock full access