Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def decode(tree: CodeTree, bits: List[Bit]): List[Char] = {
- def decodeAcc(t: CodeTree, bs: List[Bit], acc: List[Char]): List[Char] = t match {
- case Leaf( c, w ) =>
- if( bs.isEmpty )
- List(c)
- else
- decodeAcc( tree, bs, acc:::List(c) )
- case Fork( l,r,c,w ) =>
- if ( bs.head == 0 ) decodeAcc( l, bs.tail, acc )
- else decodeAcc( r, bs.tail, acc )
- }
- decodeAcc( tree, bits, List() )
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement