Advertisement
Guest User

dsf

a guest
Jun 9th, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.42 KB | None | 0 0
  1. def decode(tree: CodeTree, bits: List[Bit]): List[Char] = {
  2.     def decodeAcc(t: CodeTree, bs: List[Bit], acc: List[Char]): List[Char] = t match {
  3.       case Leaf( c, w ) =>
  4.         if( bs.isEmpty )
  5.           List(c)
  6.         else
  7.           decodeAcc( tree, bs, acc:::List(c) )
  8.       case Fork( l,r,c,w ) =>
  9.         if ( bs.head == 0 ) decodeAcc( l, bs.tail, acc )
  10.         else decodeAcc( r, bs.tail, acc )
  11.     }
  12.     decodeAcc( tree, bits, List() )
  13.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement