Haskell 趣题:树的遍历

很经典的老题了,说不定很多教材里都有,最近在好几个地方又见着了,所以在这里贴一下。
设一棵树的类型为:
写一函数 avgTree :: (Fractional t) => Tree t -> Tree t,将树中所有节点中的值 (即类型为 t 的那些值) 全部替换为它们的均值。常见的方法是遍历这棵树取均值、再遍历一次 mirror 这棵树以构造新树,这里的要求是只遍历一次。
- Login to post comments
- 233 reads
Tue, 2008/10/07 - 10:00 — roy_hu

我以前也见过
...... full content is only available to community members.
- Login to post comments
|
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> |