Unformatted text preview:

Homework BinaryTree and Recursion II 1 Write a recursive body for the following static generic method that returns a String 1 2 3 4 5 6 7 8 9 10 11 12 representation of a given BinaryTree T You cannot use the BinaryTree toString method in your solution Note that the BinaryTree must be restored i e its outgoing value must be the same as its incoming value Returns the code String prefix representation of the given code BinaryTree T param T the type of the code BinaryTree node labels param t the code BinaryTree to convert to a code String return the prefix representation of code t ensures treeToString the String prefix representation of t public static T String treeToString BinaryTree T t String s if t size 0 s else BinaryTree T left t newInstance BinaryTree T right t newInstance T root t disassemble left right s root treeToString left treeToString right return s The prefix representation of the empty tree is and the prefix representation of a non empty BinaryTree T is the string concatenation of the root followed by then by the prefix representation of the left subtree the prefix representation of the right subtree and finally Here are five examples of prefix representations of some BinaryTree Character s See if you can figure out and draw the binary trees being described a a b c a b a b c 2 Write a recursive body for the following static method that copies and returns a given BinaryTree Integer Note that the given BinaryTree must be restored i e its outgoing value must be the same as its incoming value 1 2 3 4 5 6 7 8 9 Returns a copy of the the given code BinaryTree param t the code BinaryTree to copy return a copy of the given code BinaryTree ensures copy t public static BinaryTree Integer copy BinaryTree Integer t BinaryTree Integer left t newInstance BinaryTree Integer right t newInstance int root t disassemble left right t assemble root left right return t


View Full Document

OSU CSE 1223 - Homework BinaryTree and Recursion II

Documents in this Course
Load more
Download Homework BinaryTree and Recursion II
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Homework BinaryTree and Recursion II and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Homework BinaryTree and Recursion II and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?