Last active
February 1, 2019 18:28
-
-
Save mateuszszklarek/4b21f6fcfdba7bb4db3d546dc2e8fe66 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
#!/usr/bin/swift | |
class Node { | |
var children: [Node] = [] | |
var depth: Int = 0 { | |
didSet { | |
for child in children { | |
child.depth = depth + 1 | |
} | |
} | |
} | |
} | |
let node = Node() | |
let child = Node() | |
let grandchild = Node() | |
node.children.append(child) | |
child.children.append(grandchild) | |
node.depth = 1 | |
print("Node: \(node.depth)") | |
print("Child: \(child.depth)") | |
print("Grandchild: \(grandchild.depth)") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment