Documentation ¶
Overview ¶
Package deque_int implements an efficient double ended queue to store integers. An iterator is provided with which forward and backward iteration through the deque is possible.
Index ¶
- type Deque
- func (d *Deque) Back() *Iterator
- func (d *Deque) BackItem() int
- func (d *Deque) Clear()
- func (d *Deque) Front() *Iterator
- func (d *Deque) FrontItem() int
- func (d *Deque) PopBack() int
- func (d *Deque) PopFront() int
- func (d *Deque) PushBack(item int)
- func (d *Deque) PushFront(item int)
- func (d *Deque) Size() int
- type Iterator
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Deque ¶
type Deque struct {
// contains filtered or unexported fields
}
Deque is a double ended queue that can handle items of any type.
func (*Deque) Back ¶
Back returns an iterator positioned at the back of the deque, or nil if the deque is empty.
func (*Deque) BackItem ¶
BackItem returns the item at the back of the deque. Returns the zero value when the deque is empty.
func (*Deque) Front ¶
Front returns an iterator positioned at the front of the deque, or nil if the deque is empty.
func (*Deque) FrontItem ¶
FrontItem returns the item at the front of the deque. Returns the zero value when the deque is empty.
func (*Deque) PopBack ¶
PopBack removes and returns the item from the back of the deque. Returns the zero value when the deque is empty.
func (*Deque) PopFront ¶
PopFront removes and returns the item from the front of the deque. Returns the zero value when the deque is empty.
type Iterator ¶
type Iterator struct { Value int // contains filtered or unexported fields }
Iterator points to a deque item and can be used to iterate through the deque.
Example ¶
package main import ( "fmt" "github.com/notnot/container/deque_int" ) func main() { const N = 10 deque := deque_int.New() for i := 0; i < N; i++ { deque.PushBack(i) } // iterate from front to back for it := deque.Front(); it != nil; it = it.Next() { fmt.Printf("%v", it.Value) } fmt.Println() // iterate from back to front for it := deque.Back(); it != nil; it = it.Prev() { fmt.Printf("%v", it.Value) } fmt.Println() }
Output: 0123456789 9876543210