Created
December 25, 2018 18:39
-
-
Save Ibrahimhass/b78d846fb4ff75685582a6024739d1e4 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
//: 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