Documentation ¶
Overview ¶
Package queue provides implementation to get and print formatted queue.
Example:
import "github.com/shivamMg/ppds/queue" // a queue implementation. type myQueue struct { elems []int } func (q *myQueue) push(ele int) { q.elems = append([]int{ele}, q.elems...) } func (q *myQueue) pop() (int, bool) { if len(q.elems) == 0 { return 0, false } e := q.elems[len(q.elems)-1] q.elems = q.elems[:len(q.elems)-1] return e, true } // myQueue implements queue.Queue. Notice that the receiver is of *myQueue // type - since Push and Pop are required to modify q. func (q *myQueue) Push(ele interface{}) { q.push(ele.(int)) } func (q *myQueue) Pop() (interface{}, bool) { return q.pop() } // q := myQueue{} // q.push(11) // q.push(12) // queue.Print(&q)
Index ¶
Constants ¶
View Source
const ( Arrow = "→" BoxVer = "│" BoxHor = "─" BoxDownLeft = "┐" BoxDownRight = "┌" BoxUpLeft = "┘" BoxUpRight = "└" BoxVerLeft = "┤" BoxVerRight = "├" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Queue ¶
type Queue interface { // Pop must pop and return the first element out of the queue. If queue is // empty ok should be false, else true. Pop() (ele interface{}, ok bool) // Push must insert ele in the queue. Since ele is of interface type, type // assertion must be done before inserting in the queue. Push(ele interface{}) }
Queue represents a queue of elements.
Click to show internal directories.
Click to hide internal directories.