-
Notifications
You must be signed in to change notification settings - Fork 20
/
depth-first-reverse.kt
28 lines (25 loc) · 1.09 KB
/
depth-first-reverse.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import com.intuit.commons.traverser.Traverser
import com.intuit.commons.traverser.TraversingIterator
fun main() {
// populate the company according example at the top of this discussion
val c = Company("Company")
.businessEntity(BusinessEntity("BU-Pacific")
.team(Team("PD=Product Development")
.member(Member("Sylvester Moonstone"))
.member(Member("John Smith"))
.member(Member("Lucy Gold")))
.team(Team("SL=Sales Department")
.member(Member("Nick Citrine"))
.member(Member("Kleo Ruby")))
.team(Team("MG=Management")
.member(Member("Anna Peridot"))))
// create depth-first post-order iterator
val i: TraversingIterator<Node> = Traverser
.depthFirst(Node::children)
.postOrderIterator(c)
// print names of the nodes in DFS sequence
while (i.hasNext()) {
val node: Node = i.next()
println(node.name)
}
}