ds

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2019 License: MIT Imports: 2 Imported by: 0

README

Data structures with Go

Build Status Build status Coverage Status Go Report Card GoDoc

To get this examples

go get -u github.com/rayyildiz/ds
Stack

Stack is a data type that implementation of LIFO (Last In First Out) A stack has two important method :

  • Push Insert an element to stack
  • Pop Remove the top of the element from stack.

Here is usage of stack

stack := NewStack()

stack.Push("One")
stack.Push("Two")

elem, err := stack.Pop()   // elem = "Two" and err = nil
Queue

Queue is a data type that implementation of FIFO (First In, First Out)

A queue has two important method :

  • Enqueue Insert an element to queue
  • Dequeue Remove the first element from queue

Here is usage of stack

q := NewQueue()

q.Enqueue("One")
q.Enqueue("Two")

elem, err := q.Dequeue()   // elem = "One" and err = nil
Linked List

Simple implementation of linked-list

Currently 2 method implemented:

  • Insert Insert a new element to linked list
  • Count Number of elements.

Here is usage of linked list

list := NewLinkedList()

list.Insert(3)
list.Insert("hello")
list.Insert(3.14)
list.Insert(true)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrQueue = errors.New("queue is empty")

ErrQueue is for error if queue is empty.

View Source
var ErrStack = errors.New("stack is empty")

ErrStack is error if stack is empty.

Functions

This section is empty.

Types

type LinkedList

type LinkedList struct {
	// contains filtered or unexported fields
}

LinkedList container.

func NewLinkedList

func NewLinkedList() *LinkedList

NewLinkedList : Create a new LinkedList object whose root is nil.

func (*LinkedList) Count

func (list *LinkedList) Count() int

Count : Size of elements.

func (*LinkedList) Insert

func (list *LinkedList) Insert(data interface{})

Insert : inserting new item to linked-list.

type Node

type Node struct {
	// contains filtered or unexported fields
}

Node is data container of LinkedList.

type Queue

type Queue struct {
	// contains filtered or unexported fields
}

Queue Data Container

func NewQueue

func NewQueue() *Queue

NewQueue : Create a new queue

func (*Queue) Dequeue

func (q *Queue) Dequeue() (interface{}, error)

Dequeue : Remove an item from queue (FIFO)

func (*Queue) Enqueue

func (q *Queue) Enqueue(value interface{})

Enqueue : Insert an item to queue

func (*Queue) Length

func (q *Queue) Length() int

Length of the queue

type Stack

type Stack struct {
	// contains filtered or unexported fields
}

Stack is for root and root node.

func NewStack

func NewStack() *Stack

NewStack returns a new Stack object.

func (*Stack) Length

func (stack *Stack) Length() int

Length of the stack.

func (*Stack) Pop

func (stack *Stack) Pop() (interface{}, error)

Pop returns top element from stack.(LIFO).

func (*Stack) Push

func (stack *Stack) Push(value interface{})

Push a item to the stack.

type StackItem

type StackItem struct {
	// contains filtered or unexported fields
}

StackItem is node for data.

Jump to

Keyboard shortcuts

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