nikolaj

Untitled

Jun 3rd, 2019
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.28 KB | None | 0 0
  1. class Tree(val x: Int, val left: Tree? = null, val right: Tree? = null)
  2.  
  3. fun order(T: Tree?) = sequence {
  4.     if (T == null) return@sequence
  5.     yieldAll(order(T.left))
  6.     yield(T.x)
  7.     yieldAll(order(T.right))
  8. }
  9.  
  10. fun main() = println(order(Tree(2, Tree(1), Tree(3))).toList())
Advertisement
Add Comment
Please, Sign In to add comment