base data structure and algorithm implement by go genericity
$ go get -u github.com/246859/containers@latest
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.
- fork this repository
- checkout your feature branch
- commit changes, know more about commit-messages-guide
- create a pull request to this repository