Python代写 BST : ass4代写Python编程

Introduction用python实现二叉搜索数的功能,在原来的模板基础上,增加题目要求写的方法,实现功能并且最后完成测试RequirementYou may begin this assignment with the sample BST code.Add the following functionality to the code:1. Modify the code so that each node stores not only a number (which is used as the sort value (or “key”) of the node), but also a string containing the name of a person. So, the root node of a BST may contain for its data: [40, “Wendy”], the left child of the root may be [18, “Carol”]. Modify all functions that this change affects.2. Add a function called “changeLeaves” which changes the person’s name contained in the leaf nodes to “Leif”. Recall that a leaf node is one that has no children. Your function should take one parameter, the root of a BST, and it should return the root of the (changed) tree.3. Add a function called “countNodes” that counts the number of nodes that contain names starting with “w” or “W”. Your function should take one parameter, the head of a BST and it should return the number of nodes matching the given condition.4. Add a function called “printReverse” that prints all the nodes in reverse order. That is, the node with the largest numerical value is printed first and the node with the smallest numerical value is printed last. Your function should take as a parameter the root of a BST and it should return nothing.5. Write a function that will convince the TA that your code works. Be sure to explain what you are showing. You should cover special cases such as empty trees.What to SubmitSubmit a single file containing your entire program. DO NOT ZIP THE FILE. You do not need to include the data file. We will test your program on a different grid.Be sure you document your program appropriately. Each function should include a header comment explaining what the function does, what the parameters are and what it returns.MarkingThe assignment will be marked using a rubric. Rubrics provide a guide to the TAs however they are not all inclusive. We may deduct marks for unanticipated errors.I do not give extensions on assignments. A 24 hour extension is available to everyone but comes with a 2 mark penalty. Please do not ask for another extension unless you have a very, very good reason.Academic IntegrityPlease refer to the notes on Academic Integrity. It is ok (and encouraged) to talk about solutions with your friends but please do your own work. It is also ok to take snippits of code from the internet as long as the code does not solve the entire problem. If you use snippits of code, please document it in your comments by adding a URL indicating where the code came from.“””This module implements binary search trees.The tree elements may be of any type. Duplicates are not allowed.Example for CISC 121“””# A BST node is a dict with three elements:# 1. data: the value in the node# 2. left: a reference to the left subtree# 3. right: a reference to the right subtree# Prints an indented display of the tree – useful for debugging.# The output will look kind of like a sideways version of a drawing# of the tree.def display(tree, indent=0):if tree == None: # emptypasselse:# right tree first (so it’s on the right when you tilt your# head to the left to look at the display)display(tree[‘right’],indent+1)print(“ “ * indent + str(tree[‘data’]))# now the left treedisplay(tree[‘left’],indent+1)# adds a value to a BST and returns a pointer to the modified BSTdef add(tree, value):if tree == None:return {‘data’:value, ‘left’:None, ‘right’:None}elif value tree[‘data’]:tree[‘right’] = add(tree[‘right’],value)return treeelse: # value == tree[‘data’]return tree # ignore duplicatedef printValues(tree):if tree == None:returnprintValues(tree[‘left’])print(tree[‘data’])printValues(tree[‘right’])def main():myTree = None #create an empty tree#Create a tree with the nodes [20, 2, 25, 14, 1, 23, 75, 93, 74]#Note that the add function always returns the root of the BST!myTree = add(myTree, 20)myTree = add(myTree, 2)myTree = add(myTree, 25)myTree = add(myTree, 14)myTree = add(myTree, 1)myTree = add(myTree, 23)myTree = add(myTree, 75)myTree = add(myTree, 93)myTree = add(myTree, 74)display(myTree, 0)printValues(myTree)main()本团队核心人员组成主要包括BAT一线工程师,精通德英语!我们主要业务范围是代做编程大作业、课程设计等等。我们的方向领域:window编程 数值算法 AI人工智能 金融统计 计量分析 大数据 网络编程 WEB编程 通讯编程 游戏编程多媒体linux 外挂编程 程序API图像处理 嵌入式/单片机 数据库编程 控制台 进程与线程 网络安全 汇编语言 硬件编程 软件设计 工程标准规等。其中代写编程、代写程序、代写留学生程序作业语言或工具包括但不限于以下范围:C/C++/C#代写Java代写IT代写Python代写辅导编程作业Matlab代写Haskell代写Processing代写Linux环境搭建Rust代写Data Structure Assginment 数据结构代写MIPS代写Machine Learning 作业 代写Oracle/SQL/PostgreSQL/Pig 数据库代写/代做/辅导Web开发、网站开发、网站作业ASP.NET网站开发Finance Insurace Statistics统计、回归、迭代Prolog代写Computer Computational method代做因为专业,所以值得信赖。如有需要,请加QQ:99515681 或邮箱:[email protected] 微信:codehelp

你可能感兴趣的:(Python代写 BST : ass4代写Python编程)