Question: In ocaml, we've a the two given types and a function ncompress of type ' a n _ tree - > ( ' a *
In ocaml, we've a the two given types and a function ncompress of type a ntree a int list that converts an ntree into a list of tuples. The first element of the tuple is stored in the node and the second is the number of immediate children. This follows preorder traversal.
Write a function ndecompress of typea int list a ntree that takes the a int list converts it back to an ntree. If the input list is empty, raise an Invalidarg exception using failwith because it can't represent a completely empty tree.
Can use functions found in Stdlib and List, but not any submodules of Stdlib
type 'a flat Le No of a
type 'a ntree Node of a 'a ntree list
let t Node A Node B; Node CNode D; Node FNode E; Node GNode H
let com ncompress t;;
com:string int list A; B; C; D; F; E; G; H
let deco ndecompress com;;
deco t;;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
