Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- val tt = Node(1,Node(2,Node(4,Empty,Empty),Empty),Node(3,Node(5,Empty,Node(6,Empty,Empty)),Empty));;
- sealed trait BT[+A]
- case object Empty extends BT[Nothing]
- case class Node[+A](elem:A, left:BT[A], right:BT[A]) extends BT[A]
- def breadthBT[A](tree: BT[A]) = {
- def helper[A](nodeQueue: List[BT[A]]): List[A] = nodeQueue match {
- case Nil => Nil
- case Empty :: tail => helper(tail)
- case Node(value, leftSubtree, rightSubtree) :: tail => value :: helper(tail ++ List(leftSubtree, rightSubtree))
- }
- helper (List(tree))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement