Skip to content

246859/containers

Repository files navigation

containers

Static Badge GitHub License

base data structure and algorithm implement by go genericity

install

$ go get -u github.com/246859/containers@latest

usage

Import the package and use the structure. Here is a simple example about ArrayList.

import (
    "fmt"
    "github.com/246859/containers/lists"
)

func main() {
    arrayList := lists.NewArrayList[int](10)
    arrayList.Add(1)
    arrayList.Add(2)
    arrayList.Add(3, 4, 5)

    ele, has := arrayList.Get(0)
    if !has {
       panic("element not found")
    }
    fmt.Println(ele)
}

Here is a simple example about PriorityQueue.

package main

import (
    "cmp"
    "fmt"
    "github.com/246859/containers/queues"
)

func main() {
    priorityQueue := queues.NewPriorityQueue[int](20, cmp.Compare[int])
    priorityQueue.Push(2)
    priorityQueue.Push(1)
    priorityQueue.Push([]int{0, 6, 3, 2, 5}...)

    top, has := priorityQueue.Peek()
    fmt.Println(top, has)
}

know more information to see ToDo List.

contribute

  1. fork this repository
  2. checkout your feature branch
  3. commit changes, know more about commit-messages-guide
  4. create a pull request to this repository