queue

package
Version: v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 27, 2019 License: MIT Imports: 3 Imported by: 0

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

func Print

func Print(q Queue)

Print prints the formatted queue to standard output.

func Sprint

func Sprint(q Queue) (s string)

Sprint returns the formatted queue.

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.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL