diff --git a/cmd/ll/main.go b/cmd/ll/main.go index 02688c5..ec6854f 100644 --- a/cmd/ll/main.go +++ b/cmd/ll/main.go @@ -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) diff --git a/lists/main.go b/lists/main.go index 4fb0528..e160419 100644 --- a/lists/main.go +++ b/lists/main.go @@ -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]) diff --git a/lists/single.go b/lists/single.go index 589c510..8599b98 100644 --- a/lists/single.go +++ b/lists/single.go @@ -105,8 +105,12 @@ func (ll *sLinkedList[V]) InsB(index int, values ...V) { } func (ll *sLinkedList[V]) InsA(index int, values ...V) { + if index == ll.ln-1 { + ll.Add(values...) + return + } + el := ll.getEl(index) - for _, v := range values { el.next = &sElement[V]{ value: v,