linked-list: sum and in operators

This commit is contained in:
2026-07-13 14:27:18 +02:00
parent 4df222496d
commit daca05e637
5 changed files with 39 additions and 6 deletions
+10
View File
@@ -127,3 +127,13 @@ func (ls1 *LinkedList) Clone() (ls2 *LinkedList) {
}
return
}
func (ls *LinkedList) HasValue(value any) (found bool) {
for node := ls.FirstNode(); node != nil; node = node.Next() {
if kern.Equal(node.Data(), value) {
found = true
break
}
}
return
}
+18 -3
View File
@@ -85,7 +85,7 @@ func (ls *LinkedList) PushBack(data any) (node *ListNode) {
func (ls *LinkedList) SeqPushBack(data any) (result *LinkedList) {
switch seq := data.(type) {
case kern.Iterator:
result = ls.IterPushBack(seq)
result = ls.IterPushBack(seq, false)
default:
ls.PushBack(data)
result = ls
@@ -93,9 +93,24 @@ func (ls *LinkedList) SeqPushBack(data any) (result *LinkedList) {
return
}
func (ls *LinkedList) IterPushBack(it kern.Iterator) *LinkedList {
func (ls *LinkedList) SeqClonePushBack(data any) (result *LinkedList) {
switch seq := data.(type) {
case kern.Iterator:
result = ls.IterPushBack(seq, true)
default:
ls.PushBack(data)
result = ls
}
return
}
func (ls *LinkedList) IterPushBack(it kern.Iterator, clone bool) *LinkedList {
for item, err1 := it.Next(); err1 == nil; item, err1 = it.Next() {
ls.PushBack(item)
if clone && kern.IsCloner(item) {
item = item.(kern.Cloner).Clone()
} else {
ls.PushBack(item)
}
}
return ls
}