Guest User

Untitled

a guest
Apr 22nd, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 0.89 KB | None | 0 0
  1. ;teil 2
  2.  
  3. (define code
  4.     (lambda (tree message)
  5.       (if  (empty? message)
  6.            empty
  7.            (append  (code-symbol tree (first message))
  8.                     (code tree (rest message))))))
  9.  
  10. (define code-symbol
  11.     (lambda (tree symbol)
  12.      (cond ((empty? (first (node-symbols tree))) (violation "Symbol nicht im Tree"))
  13.            ((help-symbolsearch (node-symbols tree) symbol)
  14.              (cond ((help-symbolsearch (node-symbols (node-left tree)) symbol) (cons 0 (code-symbol (node-left tree) symbol)))
  15.                    ((help-symbolsearch (node-symbols (node-right tree)) symbol) (cons 1 (code-symbol (node-left tree) symbol))))))))
  16.            
  17.    (define help-symbolsearch
  18.      (lambda (s symbol)
  19.        (cond ((empty? (first s))  (violation "Symbol nicht im Tree"))
  20.              ((string=? (first s) symbol) #t)
  21.              (else (help-symbolsearch (rest s) symbol)))))
Add Comment
Please, Sign In to add comment