Last active
May 9, 2018 06:39
-
-
Save ashalva/5ba3488b1df8c486768bcf6139b00848 to your computer and use it in GitHub Desktop.
Traversing the tree in swift.
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
class Node<T> { | |
var value:T | |
var next: Node? | |
var previous: Node? | |
init(value: T) { | |
self.value = value | |
self.next = nil | |
self.previous = nil | |
} | |
} | |
func traverse (head: Node<Int>?) { | |
var current: Node<Int>? = head | |
while let curr = current { | |
print(String(describing: (curr.value))) | |
current = curr.next | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment