Skip to content

Instantly share code, notes, and snippets.

@ashalva
Last active May 9, 2018 06:39
Show Gist options
  • Save ashalva/5ba3488b1df8c486768bcf6139b00848 to your computer and use it in GitHub Desktop.
Save ashalva/5ba3488b1df8c486768bcf6139b00848 to your computer and use it in GitHub Desktop.
Traversing the tree in swift.
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