Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please write this function in python: Rules: TreeNode class: 5 tree-print(root) Write a function, tree-print(), which takes a tree as a parameter, and prints out

Please write this function in python:

image text in transcribed

Rules:

image text in transcribed

image text in transcribed

TreeNode class:

image text in transcribed

5 tree-print(root) Write a function, tree-print(), which takes a tree as a parameter, and prints out the value stored in every node, one per line. Note that this function does not impose a particular order on you! You may print the values in any order! My testcase-grading code will be smart enough to give you full points if you print all of the correct lines - no matter what order you use. Do not print anything, if you are given an empty tree. A few of the functions will assume that the tree is a BST; however, most will not. All of the trees will be binary trees, and will use the TreeNode class that I've provided in tree_node.py . Put all of your functions into a file named tree_funcs.py Except where explicitly stated in the function descriptions below, you may choose whether to use recursion or a loop in the functions. (Note that the recursive solution will be much easier in most cases.) In this project, helper functions and default arguments) are banned. In two of the functions in this project, you may assume that the tree we pass you is not empty. But only do this if we explicitly say so! Most of your functions must handle the empty-tree case. class TreeNode: def __init__(self, val): self.val val self.left None self.right None =

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Administrator Limited Edition

Authors: Martif Way

1st Edition

B0CGG89N8Z

More Books

Students also viewed these Databases questions

Question

What is a business plan?

Answered: 1 week ago