Skip to content

Instantly share code, notes, and snippets.

@valtyriel
Created July 25, 2012 16:15
Show Gist options
  • Save valtyriel/3177024 to your computer and use it in GitHub Desktop.
Save valtyriel/3177024 to your computer and use it in GitHub Desktop.
Implementation of a deque: A doubly-linked list where items can be added or removed from either end of the list.
package deque
// A single element of the deque.
// The leftmost element has left = nil,
// and the rightmost element has right = nil.
type element struct{
// The elements to the left and right of this one.
left, right *element
// The deque to which this element belongs.
deque *Deque
// The actual value contained in this element.
value interface{}
}
// Deque represents a doubly-linked list.
type Deque struct {
left, right *element
len int
}
// Init initializes or clears a deque.
func (d *Deque) Init() Deque{
}
func (d *Deque) PushLeft(v interface{}) {
}
func (d *Deque) PushRight(v interface{}) {
}
func (d *Deque) PopLeft() interface{} {
}
func (d *Deque) PopRight() interface{} {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment