Skip to content

Instantly share code, notes, and snippets.

@Ibrahimhass
Created December 25, 2018 18:39
Show Gist options
  • Save Ibrahimhass/b78d846fb4ff75685582a6024739d1e4 to your computer and use it in GitHub Desktop.
Save Ibrahimhass/b78d846fb4ff75685582a6024739d1e4 to your computer and use it in GitHub Desktop.
//: Append data to linked List
extension LinkedList {
func append(_ node : Node) {
//Check for empty Linked List and assign the node to head if empty
guard head != nil else {
head = node
return
}
var current = head
// Loop to the last element in the Linked List
while let _ = current?.next {
current = current?.next
}
// Retrieved the last element
current?.next = node
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment