-
Notifications
You must be signed in to change notification settings - Fork 0
/
TreeWriter.scm
37 lines (37 loc) · 1.17 KB
/
TreeWriter.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
(define display-tree
(lambda (tr)
(let* ([p (process "java -jar TreeViewer.jar")]
[in (car p)] [out (cadr p)][invalid-tree '!$&])
(let loop ([tr tr])
(cond
[(empty-tree? tr)
;; (write "E" out)
(write-char #\newline out)]
[(leaf? tr)
(write 'L out)
(write (root-value tr) out)
(write-char #\newline out)
(loop (left-subtree tr))
(loop (right-subtree tr))]
[(tree? tr)
(write 'T out)
(write (root-value tr) out)
(write-char #\newline out)
(loop (left-subtree tr))
(loop (right-subtree tr))]
[(node? tr)
(write 'N out)
(write (root-value tr) out)
(write-char #\newline out)
(loop (left-subtree tr))
(loop (right-subtree tr))]
[else
(write 'I out)
(write tr out)
(write-char #\newline out)
(write-char #\newline out)
(write-char #\newline out)]))
(write-char #\newline out)
(flush-output-port out)
(close-output-port out)
(close-input-port in))))