Question: my code: public String serialize() { return serialize(root); } private String serialize(BTNode node) { if (node == null) { return X(NULL); } if (node.getLeft() ==

 my code: public String serialize() { return serialize(root); } private String my code:

public String serialize() { return serialize(root); }

private String serialize(BTNode node) { if (node == null) { return "X(NULL)"; } if (node.getLeft() == null && node.getRight() == null) { return "L(" + node.getKey() + ")"; } if (node.getLeft() == null || node.getRight() == null) { return "X(" + node.getKey() + ")," + serialize(node.getLeft() != null ? node.getLeft() : node.getRight()); } String left = serialize(node.getLeft()); String right = serialize(node.getRight()); return "I(" + node.getKey() + ")," + left + "," + right; } Tester:

package cs1501_p1;

public class BST> implements BST_Inter { private BTNode root = null;

public void put(T key) // Add a new key to the BST { BTNode node = root; newNode.setLeft(reverse(reversed.getRight())); newNode.setRight(reverse(reversed.getLeft())); return newNode; } } output:

Successfully built an empty tree! FAILED Expected: R(10),I(5),L(2),X(NULL),I(37),X(NULL),L(45) Actual: X(45),X(37),X(10),X(2),L(5) please fix and help!!!

serialize() : Perform a pre-order traversal of the BST in order to produce a String representation of the BST. The reprsentation should be a comma separated list where each entry represents a single node. Each entry should take the form: type(key). You should track 4 node types: R : The root of the tree - I: An interior node of the tree (e.g., not the root, not a leaf) - L: A leaf of the tree - x : A stand-in for a null reference For each node, you should list its left child first, then its right child. You do not need to list children of leaves. The x type is only for nodes that have one valid child. The key for an x node should be NULL (all caps). Consider the following

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!