Difference between revisions of "Binary Int Tree Assignment"
Jump to navigation
Jump to search
| Line 2: | Line 2: | ||
Prepare for the [[Binary_Search_Tree_Assignment|Binary Search Tree]] Exercise with a simpler warm up. | Prepare for the [[Binary_Search_Tree_Assignment|Binary Search Tree]] Exercise with a simpler warm up. | ||
| − | = | + | =int_tree= |
| − | |||
| − | |||
| − | |||
datatype int_tree = NODE of (int_tree * int * int_tree) | EMPTY | datatype int_tree = NODE of (int_tree * int * int_tree) | EMPTY | ||
| + | =Examples= | ||
<!-- | <!-- | ||
[[File:Sorted binary tree inorder.svg|Sorted binary tree inorder|frame|LNR would produce: ABCDEFGHI<br>RNL would produce: IHGFEDCBA]] | [[File:Sorted binary tree inorder.svg|Sorted binary tree inorder|frame|LNR would produce: ABCDEFGHI<br>RNL would produce: IHGFEDCBA]] | ||
--> | --> | ||
| + | |||
| + | =Code to Implement= | ||
| + | {{SMLToImplement|warmup_binary_int_tree|sum|binary_int_tree}} | ||
==sum== | ==sum== | ||
Revision as of 03:58, 21 October 2022
Contents
Motivation
Prepare for the Binary Search Tree Exercise with a simpler warm up.
int_tree
datatype int_tree = NODE of (int_tree * int * int_tree) | EMPTY
Examples
Code to Implement
| file: | src/main/sml/binary_int_tree/warmup_binary_int_tree.sml | |
| functions: | sum |
sum
fun sum(node : int_tree) : int =
raise Fail("NotYetImplemented")
sum_accumulate
fun sum_accumulate(init : int, node : int_tree) : int =
raise Fail("NotYetImplemented")
fold_rnl
(*
* depth-first, reverse in-order traversal
* https://en.wikipedia.org/wiki/Tree_traversal#Reverse_in-order_(RNL)
*)
fun fold_rnl(f : (int * 'a) -> 'a, init : 'a, node : int_tree) : 'a =
raise Fail("NotYetImplemented")
Testing
| source folder: | src/test/sml/warmup_binary_int_tree |
| how to run with CM.make verbosity off: | sml -Ccm.verbose=false run_binary_int_tree_testing.sml |
| how to run with CM.make verbosity on: | sml run_binary_int_tree_testing.sml |
note: ensure that you have removed all printing to receive credit for any assignment.