pa4.fs

Run Settings
LanguageF#
Language Version
Run Command
let findVolume tuple = let (length, width, height) = tuple length * width * height let rec maxCubeVolume cubes = match cubes with | [] -> 0.0 | hd::tl -> let otherMaxVolumes = maxCubeVolume tl // finds max vol of the rest of the list let volume = findVolume hd if volume > otherMaxVolumes then volume else otherMaxVolumes // #2: // not including list return type because it is implied let rec findMatches (element:string) (list: (string * int) list) = match list with | [] -> [] | (str, num)::tl -> // adds integer corresponding to the result, keeps searching // if str doesn't match, continues searching without adding anything to the list if str = element then num::(findMatches element tl) else (findMatches element tl) // #3: type BST = | Empty | TreeNode of int * BST * BST let rec insert value tree = match tree with | Empty -> TreeNode(value, Empty, Empty) // if empty, add value | TreeNode(value, left_sub, right_sub) when value = value -> tree // insert value into the left subtree | TreeNode(value, left_sub, right_sub) when value < value -> TreeNode(value, insert value left_sub, right_sub) // insert value into the right subtree | TreeNode(value, left_sub, right_sub) -> TreeNode(value, left_sub, insert value right_sub) let rec contains value tree = match tree with | Empty -> false | TreeNode(value, left_sub, right_sub) when value = value -> true // checks left subtree for value | TreeNode(value, left_sub, right_sub) when value < value -> contains value left_sub // checks right subtree for value | TreeNode(value, left_sub, right_sub) -> contains value right_sub let rec count func tree = match tree with | Empty -> 0 // counts left_sub and righ_sub by calling TreeNode recursively | TreeNode(value, left_sub, right_sub) -> let countLeft = count func left_sub // need return stmt? is the func unused and thats why error is thrown? let countRight = count func right_sub // sum the node counts after confirmation let countCurrent = if func value then 1 else 0 countLeft + countRight + countCurrent // uses lambda func to call count func and check even ints in tree let evenCount tree = count (fun x -> x % 2) tree
Editor Settings
Theme
Key bindings
Full width
Lines