...
This commit is contained in:
parent
d9f2a304dc
commit
5ed3237e00
3 changed files with 14 additions and 10 deletions
|
@ -3,20 +3,17 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
"github.com/reklesio/gods/lists"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
list := lists.NewSingly[string]("zero", "one", "two", "three", "four", "five")
|
||||
fmt.Println(list)
|
||||
list.InsA(0, "after-1", "after-2")
|
||||
fmt.Println(list)
|
||||
list.InsB(0, "-two", "-one")
|
||||
fmt.Println(list)
|
||||
|
||||
|
||||
|
||||
//list.Swap(0, 2)
|
||||
fmt.Println(list)
|
||||
uList := lists.NewSingly(list.Values()...)
|
||||
for i, v := range uList.Values() {
|
||||
uList.Set(i, strings.ToUpper(v))
|
||||
}
|
||||
fmt.Println(uList)
|
||||
|
||||
intList := lists.NewSingly[int](100, 5, -1, 1000, 200, 1337)
|
||||
fmt.Println(intList)
|
||||
|
|
|
@ -31,6 +31,9 @@ type List[V any] interface {
|
|||
// Swap elements by indexes specified in arguments.
|
||||
Swap(i, j int)
|
||||
|
||||
// Return channel with all the values.
|
||||
Chan() chan V
|
||||
|
||||
// The sort function that gets the Less function as argument
|
||||
// and sorts the list corresponding to it.
|
||||
Sort(gods.LessFunc[V])
|
||||
|
|
|
@ -105,8 +105,12 @@ func (ll *sLinkedList[V]) InsB(index int, values ...V) {
|
|||
}
|
||||
|
||||
func (ll *sLinkedList[V]) InsA(index int, values ...V) {
|
||||
el := ll.getEl(index)
|
||||
if index == ll.ln-1 {
|
||||
ll.Add(values...)
|
||||
return
|
||||
}
|
||||
|
||||
el := ll.getEl(index)
|
||||
for _, v := range values {
|
||||
el.next = &sElement[V]{
|
||||
value: v,
|
||||
|
|
Loading…
Reference in a new issue