正在加载图片...
6.001, Spring Semester, 2005--Quiz Il art Gu ol c EaO五i Here is a definit ion of a hig her order procedure for performing computat ions on trees(w here trees are represented as a list, w hose element s are eit her leaves(i.e, values such as numbers or sy mbols) or ot her trees). You may assume that leaf? is a predicate that returns true for any object that is ot a tree: (define (process-tree tr leaf-op combine init) if (null? tr) ini七 (if (leaf? tr) (leaf-op tr (combine (process-tree (car tr) leaf-op combine init) (process-tree (cdr tr) leaf ombine init))))) Below are a set of descript ions of operat ions on trees A: ret urns a new copy of the input tree B: ret urns a pointer to the original input tree C: sums the values of the leaves of the input tree D: sums the values of t he even-valued leaves of the input tree E: sums the values of the odd- valued leaves of the input tre reverses the top level of the input tree G: deep reverses the input tree(i.e. reverses each level of the tree count s the numbers of leaves in the input tree I: ret urns the value of the first leaf of the input tree J: flattens the input tree(i. e, ret urns a single list of all the elements of the tree in order K: none of the above￾       J      %  =   ))     %  % ?,) %  % %  %& ,)% %  ) -% ?!!& -% %) % 0%  %.0%B  ) %B!  . %% )  %   ) %   . 0 1 ) %   2 ￾ ￾'     '   ￾ ￾   ￾ ￾  ￾ '  ￾  ￾'   ￾    '   ￾'   ￾    '   9,   %  %%  %  %2 2 %  , .  )   92 %    )    2 %% ) -%  ) -%  )   2 %% ) -%  ) -7- -%  )   2 %% ) -%  ) 7- -%  )   2 -%% )  -  )   2  -%% )   ?!! -%% ) -  ) B 2 % ) 0%  -%  )   2 % ) -  ) =%   )   K2 F% )   ?!!& %  % %   ) %  )   B 82   ) 0-
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有