Skip to content

earthboundkid/deque

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

deque GoDoc Coverage Status

Deque is deque container using Go generics.

Wikipedia says:

In computer science, a double-ended queue (abbreviated to deque, pronounced deck, like "cheque") is an abstract data type that generalizes a queue, for which elements can be added to or removed from either the front (head) or back (tail).

Usage

// Make a new deque of ints
d := deque.Of(9, 8, 7, 6)

// Sort it
sort.Sort(deque.Sortable[int]{d})
// d is 6, 7, 8, 9

// Add 5, 4, 3, 2, 1 to the front
for i := 5; i > 0; i-- {
    d.PushFront(i)
}

// Deque{ len: 9, cap: 16, items: [1, 2, 3, 4, 5, 6, 7, 8, 9]}
fmt.Println(d)

// Now pop items off the tail
// Prints 9 8 7 6 5 4 3 2 1
for {
    n, ok := d.RemoveBack()
    if !ok {
        break
    }
    fmt.Print(n, " ")
}
fmt.Println()

About

Generic deque container

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Languages