Singly-linked list/Element insertion: Difference between revisions

Line 862:
 
=={{header|Julia}}==
<lang{{works with|Julia>|0.6}}
See the <tt>LinkedList</tt> implemented at [[Singly-linked_list/Element_definition#Julia]].
mutable struct Node
 
nextnode
<lang julia>function Base.insert!(ll::LinkedList{T}, index::Integer, item::T) where T
function Node(nxt)
if index this == new()1
this.nextnodeif = nxtisempty(ll)
this return push!(ll, item)
else
ll.head = Node{T}(item, ll.head)
end
else
thisnd = new()ll.head
while index > 2
if nd.next isa EmptyNode
throw(BoundsError())
else
nd = nd.next
index -= 1
end
end
nd.next = Node{T}(item, nd.next)
end
functionreturn Node()ll
end</lang>
this = new()
end
end
 
function insert_after(prior, middle)
middle.nextnode = prior.nextnode
prior.nextnode = middle
end
 
c = Node()
a = Node(c)
b = Node()
insert_after(a, b)
</lang>
 
=={{header|Kotlin}}==
Anonymous user