github.com/djordje200179/extendedlibrary/datastructures@v1.7.1-0.20240227175559-d09520a92dd4/seqs/sequences.go (about) 1 package seqs 2 3 // Queue is a first-in-first-out data structure. 4 type Queue[T any] interface { 5 Empty() bool // Empty returns true if the queue is empty. 6 7 PushBack(value T) // PushBack adds a value to the back of the queue. 8 PopFront() T // PopFront removes and returns the value at the front of the queue. 9 } 10 11 // PeekableQueue is a queue that allows peeking at the front value. 12 type PeekableQueue[T any] interface { 13 Queue[T] 14 15 PeekFront() T // PeekFront returns the value at the front of the queue without removing it. 16 } 17 18 // Stack is a last-in-first-out data structure. 19 type Stack[T any] interface { 20 Empty() bool // Empty returns true if the stack is empty. 21 22 PushBack(value T) // PushBack adds a value to the back of the stack. 23 PopBack() // PopBack removes the value at the back of the stack. 24 } 25 26 // PeekableStack is a stack that allows peeking at the back value. 27 type PeekableStack[T any] interface { 28 Stack[T] 29 30 PeekBack() T // PeekBack returns the value at the back of the stack without removing it. 31 } 32 33 // Deque is a double-ended queue. 34 // Values can be added and removed from both the front and back. 35 type Deque[T any] interface { 36 Queue[T] 37 Stack[T] 38 } 39 40 // PeekableDeque is a deque that allows peeking at both the front and back values. 41 type PeekableDeque[T any] interface { 42 PeekableQueue[T] 43 PeekableStack[T] 44 }