Jump to content

Doubly-linked list/Traversal: Difference between revisions

→‎{{header|Kotlin}}: Updated example see https://github.com/dkandalov/rosettacode-kotlin for details
No edit summary
(→‎{{header|Kotlin}}: Updated example see https://github.com/dkandalov/rosettacode-kotlin for details)
Line 818:
=={{header|Kotlin}}==
To complete this task, we just need to add a couple of traversal functions to the class we defined in the [[Doubly-linked list/Definition]] task:
<lang scala>// version 1.1.12
 
class LinkedList<E> {
Line 862:
fun insert(after: Node<E>?, value: E) {
if (after == null)
addFirst(value)
else if (after == last)
addLast(value)
else {
val next = after.next
val new = Node(value, after, next)
after.next = new
Line 886:
}
return sb.toString()
}
}
 
Cookies help us deliver our services. By using our services, you agree to our use of cookies.