2012年11月16日星期五

week 10: Test 2 and gtree

This week we study hor to wtire the oder about the gthree. Basically, we need to difine tree nodes and small trees. After that we should write the list the labels from a gtree. We also have to noice flatten and depth.
For flatten (just a part of it)
; If L is a list, flatten (un-nest) it, otherwise
; make it a list
(check-expect (flatten 5) (list 5))
(check-expect (flatten L1)
              (list 1 2 3 4 5 6 7 8 9 1 2 3))
For depth( just a part of it)
(check-expect (depth 3) 0)
(check-expect (depth (list 3)) 1)
(check-expect (depth (list 1 (list 2) 3))2)  -----> may test on quiz
;
(define (depth L)
  (cond
    [(not (list? L)) 0]
    [else (add1 (apply max (map depth L)))]))

没有评论:

发表评论