level 1
例如:
Input:((id = id + id)(if bool then (id = const / const)(id = id + id))(while bool (id = id -
const)(id = id - id)))
Output:(NumberOfStatements: 7 MaximumDepth: 1)
求大神帮忙!!
2012年11月27日 13点11分
1
level 1
(define (all-statement t)
(cond ((pair? t)
(cond ((null? (cdr t)) (+ 1 (all-statement (car t))))
(else (+ (all-statement (car t)) (all-statement (cdr t)))))
)
(else 0)))
(define (max-depth t)
(cond ((pair? t)
(cond ((null? (cdr t)) (+ 1 (max-depth (car t))))
(else (max (+ 1 (max-depth (car t))) (max-depth (cdr t)))))
)
(else 0)))
(define (visual-depth t)
(- (max-depth t) 2))
(define (visual-statement t)
(- (all-statement t) 1))
(define (tree-an t)
(newline)
(display "NumberOfStatements:")
(display (visual-statement t))
(display " MaximumDepth:")
(display (visual-depth t)))
2012年12月13日 12点12分
2
level 1
> (tree-an '((id = id + id)(if bool then (id = const / const)(id = id + id))(while bool (id = id -
const)(id = id - id)))) NumberOfStatements:7 MaximumDepth:1
这个是运行结果
2012年12月13日 12点12分
3