linked-list: sum and in operators
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user