Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
让我们在 ocaml 中定义一个类型树。
type 'a tree = T of 'a * 'a list;;
我想以两种方式遍历此图:(1)从根到叶(2)从叶到根
你能帮助我吗?
type 'a tree = T of 'a * 'a tree list let rec walk_downwards f = function | T (elt, children) -> f elt; List.iter (walk_downwards f) children let rec walk_upwards f = function | T (elt, children) -> List.iter (walk_upwards f) children; f elt