Skip to content

Commit 2cd8f52

Browse files
authored
Merge pull request #883 from chengchingwen/master
fix append! iterable to MutableLinkedList
2 parents b462388 + 5725e7a commit 2cd8f52

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/mutable_list.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,9 @@ end
165165

166166
function Base.append!(l::MutableLinkedList, elts...)
167167
for elt in elts
168-
push!(l, elt)
168+
for v in elt
169+
push!(l, v)
170+
end
169171
end
170172
return l
171173
end
@@ -213,6 +215,14 @@ function Base.push!(l::MutableLinkedList{T}, data) where T
213215
return l
214216
end
215217

218+
function Base.push!(l::MutableLinkedList{T}, data1, data...) where T
219+
push!(l, data1)
220+
for v in data
221+
push!(l, v)
222+
end
223+
return l
224+
end
225+
216226
function Base.pushfirst!(l::MutableLinkedList{T}, data) where T
217227
oldfirst = l.node.next
218228
node = ListNode{T}(data)

test/test_mutable_list.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,13 @@
101101
@test l2 == MutableLinkedList{Int}()
102102
@test collect(l) == collect(MutableLinkedList{Int}(1:2n...))
103103
l3 = MutableLinkedList{Int}(1:n...)
104-
append!(l3, n+1:2n...)
104+
append!(l3, n+1:2n)
105105
@test l3 == MutableLinkedList{Int}(1:2n...)
106106
@test collect(l3) == collect(MutableLinkedList{Int}(1:2n...))
107+
l4 = MutableLinkedList{Int}(1:n...)
108+
push!(l4, n+1:2n...)
109+
@test l4 == MutableLinkedList{Int}(1:2n...)
110+
@test collect(l4) == collect(MutableLinkedList{Int}(1:2n...))
107111
end
108112

109113
@testset "delete" begin

0 commit comments

Comments
 (0)