structs

package module
v0.0.0-...-c283f9b Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2017 License: MIT Imports: 3 Imported by: 0

README

structs

Whoo! Data Structures (Only Include Basic Operations)

Installation

Make sure you have you set your GOPATH (https://github.com/golang/go/wiki/GOPATH). Type the command below to install the package.

$ go get github.com/carljoshua/structs

Usage

Import the package and then create the data structure you need. Simple as that. The data structures that are included in this package are:

  • Stack
  • Queue
  • Linked List
  • Heap
package main

import (
    "github.com/carljoshua/structs"
    "reflect"
)

func main(){
  s := structs.NewStack(reflect.Int, 4)
  s.Push(1)
  s.Push(2)
  s.Pop()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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

Linked List Head

func NewList

func NewList(d_type reflect.Kind) *Head

NewList() creates the head node of the Linked List

func (*Head) Get

func (l *Head) Get(key int) interface{}

Get() returns the element in the given index

func (*Head) Insert

func (l *Head) Insert(key int, v interface{})

Insert() adds the an element into the given index If the index exceeds the length of the list, the element will be added at the last

func (*Head) Print

func (l *Head) Print()

Print() prints the data in the list into the console

func (*Head) Remove

func (l *Head) Remove(key int)

Remove() removes an element in the given index

type Heap

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

func NewHeap

func NewHeap() *Heap

NewHeap() returns a heap

func (*Heap) Insert

func (h *Heap) Insert(v ...int)

Insert() stores any number of parameters into the heap

func (*Heap) MaxHeap

func (h *Heap) MaxHeap()

MaxHeap() converts the heap into a max-heap

func (*Heap) MaxHeapTest

func (h *Heap) MaxHeapTest() bool

MaxHeapTest() evaluate the heap if it is a max-heap

func (*Heap) MinHeap

func (h *Heap) MinHeap()

MinHeap() converts the heap into a min-heap

func (*Heap) MinHeapTest

func (h *Heap) MinHeapTest() bool

MinHeapTest() evaluate the heap if it is a min-heap

func (*Heap) Print

func (h *Heap) Print()

Print() prints the data in the heap into the console

type ListNode

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

Linked List Node

type Queue

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

func NewQueue

func NewQueue(dt reflect.Kind, l int) *Queue

NewQueue() creates a Queue

func (*Queue) Dequeue

func (q *Queue) Dequeue()

Dequeue() removes the bottom-most element in the Queue

func (*Queue) Enqueue

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

Enqueue() adds an element inside the Queue if the Queue is not full

func (*Queue) IsEmpty

func (q *Queue) IsEmpty() bool

IsEmpty() returns true if the Queue is empty, otherwise false

func (*Queue) IsFull

func (q *Queue) IsFull() bool

IsFull() returns true if the Queue is full, otherwise false

func (*Queue) Peek

func (q *Queue) Peek() interface{}

Peek() returns the bottom-most element in the Queue

func (*Queue) Print

func (q *Queue) Print()

Print() prints the data in the queue into the console

type Stack

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

func NewStack

func NewStack(dt reflect.Kind, l int) *Stack

NewStack() returns a Stack

func (*Stack) IsEmpty

func (s *Stack) IsEmpty() bool

IsEmpty() returns true if the Stack is empty, otherwise false

func (*Stack) IsFull

func (s *Stack) IsFull() bool

IsFull() returns true if the Stack is full, otherwise false

func (*Stack) Pop

func (s *Stack) Pop()

Pop() removes the top-most element in the Stack

func (*Stack) Print

func (s *Stack) Print()

Print() prints the data in the stack into the console

func (*Stack) Push

func (s *Stack) Push(v interface{})

Push() adds an element into the Stack if the Stack is not full It also checks the data type of the value before storing it in the stack

func (*Stack) Top

func (s *Stack) Top() interface{}

Top() return the top-most element in the Stack

Jump to

Keyboard shortcuts

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