Created
August 2, 2018 06:08
-
-
Save laevandus/4aee49d2ebf5c331d59fef761a92a175 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension LinkedList { | |
@discardableResult func insert<T>(_ node: Node<T>, after: Node<T>) -> Node<T> { | |
node.next = after.next | |
after.next = node | |
return node | |
} | |
@discardableResult mutating func prepend(_ node: Node<T>) -> Node<T> { | |
node.next = first | |
self.first = node | |
return node | |
} | |
@discardableResult func remove(after node: LinkedList<T>.Node<T>) -> LinkedList<T>.Node<T>? { | |
let removed = node.next | |
node.next = node.next?.next | |
return removed | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment