(define-struct t-node (label children))
;; A general tree (gen-tree) is either
;; a string or
;; a structure (make-t-node l c), where
;; l is a string and
;; c is a tree-list.
;; A tree-list is either
;; empty or
;; (cons t tlist), where
;; t is a gen-tree and
;; tlist is a tree-list.
(define-struct single-product (name origin))
;; A single-product is a structure (make-single-product n o), where
;; n is a string and
;; o is a string denoting the country of origin.
(define-struct sales-product (ID prod))
;; A sales-product is a structure (make-sales-product i p), where
;; i is an integer and
;; p is either a single-product or a product-list.
;; A product-list is either
;; empty or
;; (cons sp pl), where
;; sp is a sales-product and
;; pl is a product-list.
(define (node-count-list alog)
(cond
[(empty? alog) 0]
[else (+ (node-count (first alog))
(node-count-list (rest alog)))]))
(define (node-count g)
(cond
[(string? g) 1]
[(t-node? g) (+ 1 (node-count-list (t-node-children g)))]))
No comments:
Post a Comment