Skip to content

Commit 5725e7a

Browse files
committed
add push api with multiple input and update test
1 parent 89a2836 commit 5725e7a

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/mutable_list.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,14 @@ function Base.push!(l::MutableLinkedList{T}, data) where T
215215
return l
216216
end
217217

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+
218226
function Base.pushfirst!(l::MutableLinkedList{T}, data) where T
219227
oldfirst = l.node.next
220228
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)