Skip to content

Instantly share code, notes, and snippets.

@chriswebb09
Created May 11, 2017 18:43
Show Gist options
  • Save chriswebb09/decaf5f8f56371dfec36d113f5ff9571 to your computer and use it in GitHub Desktop.
Save chriswebb09/decaf5f8f56371dfec36d113f5ff9571 to your computer and use it in GitHub Desktop.
class LinkedList<T> {
public typealias Node = LLNode<T>
private var head: Node?
private var tail: Node?
var isEmpty: Bool {
return head == nil
}
var first: Node? {
return head
}
var last: Node? {
return tail
}
func append(value: T) {
let newNode = Node(value: value)
if let lastNode = last {
newNode.previous = lastNode
lastNode.next = newNode
} else {
head = newNode
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment