Singly-linked list/Element removal: Difference between revisions
Content added Content deleted
(Added C implementation.) |
|||
Line 310: | Line 310: | ||
</lang> |
</lang> |
||
No label, no nasty literal GO TO - even though an "END DO" hides one. |
No label, no nasty literal GO TO - even though an "END DO" hides one. |
||
=={{header|Julia}}== |
|||
{{works with|Julia|0.6}} |
|||
See the <tt>LinkedList</tt> defined at [[Singly-linked_list/Element_definition#Julia]]. |
|||
<lang julia>function Base.deleteat!(ll::LinkedList, index::Integer) |
|||
if isempty(ll) throw(BoundsError()) end |
|||
if index == 1 |
|||
ll.head = ll.head.next |
|||
else |
|||
nd = ll.head |
|||
index -= 1 |
|||
while index > 1 && !isa(nd.next, EmptyNode) |
|||
nd = nd.next |
|||
index -= 1 |
|||
end |
|||
if nd.next isa EmptyNode throw(BoundsError()) end |
|||
nx = nd.next |
|||
nd.next = nd.next.next |
|||
end |
|||
return ll |
|||
end</lang> |
|||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |