Question
Solve in Standard Meta Language of New Jersey (SML) and use only recursive definitions built up from the basic built-in functions! In SML, a polymorphic
Solve in Standard Meta Language of New Jersey (SML) and use only recursive definitions built up from the basic built-in functions!
In SML, a polymorphic binary tree type with data both at the leaves and interior nodes might be represented as follows: datatype 'a Tree = LEAF of 'a | NODE of 'a * ('a Tree) * ('a Tree)
Write a function depthScan that takes a tree of type 'a Tree and returns a list of the a values stored in the leaves and the nodes. The order of the elements in the output list should be based on the depth-first post-order traversal of the tree. The type of the depthScan function should be: 'a Tree -> 'a list
Examples:
> depthScan (NODE("Science",NODE ("and",LEAF "School", NODE("Engineering", LEAF "of",LEAF "Electrical")),LEAF "Computer")) ["School","of","Electrical","Engineering","and","Computer","Science"]
> depthScan (NODE(1, NODE (2, NODE(3, LEAF 4 ,LEAF 5),LEAF 6), NODE(7,LEAF 8,LEAF 9)))
[4,5,3,6,2,8,9,7,1]
> depthScan (LEAF 4)
[4]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started