Question: Write a bst-preorder-visitor function that implements a pre-order traversal visitor pattern on the example BST implementation. Your implementation should take the same three parameters as
Write a bst-preorder-visitor function that implements a pre-order traversal visitor pattern on the example BST implementation. Your implementation should take the same three parameters as the list-visitor function.
Input: The visitor function should take three arguments: T a BST to be traversed visitor function to be called on each value in the BST. The function takes two arguments: a value stored in a BST node and the partial result. The function returns a new partial result. partial-result the partial result returned by the last call to visitor function.
Processing: You may assume that the BST is valid and include the dummy node in the computations. I.e., assume the dummy node is part of the BST. No error checking is necessary. You may assume that appropriate arguments will be passed to bst-preorder-visitor
Return: bst-preorder-visitor should return the result of applying the visitor function to each value in the BST in a preorder fashion. You should test your code and we will test your code as well.
The following is an example of list-visitor pattern
(define list-visitor (lambda (L visitor partial-result)
(if (null? L)
partial-result
(list-visitor (cdr L) visitor (visitor (car L) partial-result))
)
)
)
More details
The function list-visitor takes three arguments: a list L, a visitor function, and a partial result. It recursively visits each element in the list. At each element, list-visitor calls the visitor function and passes to it the first of L and the partial result. The visitor function returns a new partial result, which is used as the partial result for the next call to list-visitor. If L is empty, then the partial result is returned.
The visitor function passed to the list-visitor is commonly called an aggregator because it aggregates the values in the list to compute the result. For example, the + function would be considered an aggregator.
That's all I have and all you need to solve this question





\fChanging a Copy of a List Write a function called copy me that takes as input a list, and returns a copy of the list with the following changes: . Strings have all their letters converted to upper-case . Integers and floats have their value increased by 1 . booleans are negated (False becomes True, True becomes False) . Lists are replaced with the word "List" The function should leave the original input list unchanged (i.e., do not mutate the list) Mutating a List Write a function called mutate me that takes as input a list, returns None, and changes the input list in the following ways: . Strings have all their letters converted to upper-case . Integers and floats have their value increased by 1 . booleans are negated (False becomes True, True becomes False) . Lists are replaced with the word "List" So we're performing the same task, but this time we're changing the list itself instead of making a copy to return.j Write a Python function that takes two lists A and B as input parameters and returns a list C that contains all elements that lists A and B have in common, as long as elements in list A end with character 'y'. Consider a text file, named email. txt. This file contains email addresses of individuals with the following format: name@institution.domain on each line of the file. Write a Python function, called EmailInfo, that returns a list L containing sublists of the form [name, institution, domain] for all emails contained in the file email.txt.\fComputer Science - In PYTHON Tutorial Objectives . Practice working with nested lists . Practice writing code to search and sort, and evaluate run-time complexity, as well as the other control structures and data types we have used previously. Part 1a - Generating a grid Write a function called generateRandomGrid(n) that takes an integer as argument and retums an n xin grid filled with random numbers in the range [1,100]. Note the term grid here refers to a 2D (nested) list with equal width and height. For example, grid = generateRandomGrid(4) print(grid) = [[76,11,85,33],[65,64,12,3],[52.55,55,89],[17,47,68,5]] Part 1b - Searching a grid Write a function called searchGrid (g) that takes a nested list as argument and returns the smallest element in that list. For example, search Grid(grid) - 3
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
