...
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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/reklesio/gods/lists"
|
"github.com/reklesio/gods/lists"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
list := lists.NewSingly[string]("zero", "one", "two", "three", "four", "five")
|
list := lists.NewSingly[string]("zero", "one", "two", "three", "four", "five")
|
||||||
fmt.Println(list)
|
fmt.Println(list)
|
||||||
list.InsA(0, "after-1", "after-2")
|
uList := lists.NewSingly(list.Values()...)
|
||||||
fmt.Println(list)
|
for i, v := range uList.Values() {
|
||||||
list.InsB(0, "-two", "-one")
|
uList.Set(i, strings.ToUpper(v))
|
||||||
fmt.Println(list)
|
}
|
||||||
|
fmt.Println(uList)
|
||||||
|
|
||||||
|
|
||||||
//list.Swap(0, 2)
|
|
||||||
fmt.Println(list)
|
|
||||||
|
|
||||||
intList := lists.NewSingly[int](100, 5, -1, 1000, 200, 1337)
|
intList := lists.NewSingly[int](100, 5, -1, 1000, 200, 1337)
|
||||||
fmt.Println(intList)
|
fmt.Println(intList)
|
||||||
|
|
|
@ -31,6 +31,9 @@ type List[V any] interface {
|
||||||
// Swap elements by indexes specified in arguments.
|
// Swap elements by indexes specified in arguments.
|
||||||
Swap(i, j int)
|
Swap(i, j int)
|
||||||
|
|
||||||
|
// Return channel with all the values.
|
||||||
|
Chan() chan V
|
||||||
|
|
||||||
// The sort function that gets the Less function as argument
|
// The sort function that gets the Less function as argument
|
||||||
// and sorts the list corresponding to it.
|
// and sorts the list corresponding to it.
|
||||||
Sort(gods.LessFunc[V])
|
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) {
|
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 {
|
for _, v := range values {
|
||||||
el.next = &sElement[V]{
|
el.next = &sElement[V]{
|
||||||
value: v,
|
value: v,
|
||||||
|
|
Loading…
Reference in a new issue