Форум на Kuban.ru (http://forums.kuban.ru/)
-   Разработка программ (http://forums.kuban.ru/f1024/)
-   -   Хвостовая рекурсия (http://forums.kuban.ru/f1024/hvostovaya_rekursiya-6286301.html)

40KHYTbIU 19.11.2014 15:30

Хвостовая рекурсия
 
Простая задачка поиска глубины двоичного дерева, как ее в подхвост загнать не пойму. Есть идеи?

[code]
case class BTree(left: BTree, right: BTree)

def length(btree: BTree): Int =
btree match **
case BTree(left, right) => math.max(length(left), length(right)) + 1
case _ => 0
**
[/code]

wayerr 19.11.2014 17:54

[url]http://stackoverflow.com/questions/9323036/tail-recursive-function-to-find-depth-of-a-tree-in-ocaml?lq=1[/url]


Текущее время: 06:48. Часовой пояс GMT +3.