Question: Need some help for this method which is public BinaryTree(String t, String open, String close, String empty) public class BinaryTree { //Implements a Binary Tree

Need some help for this method which is public BinaryTree(String t, String open, String close, String empty)

public class BinaryTree {

//Implements a Binary Tree of Strings

private class Node {

private Node left;

private String data;

private Node right;

private Node parent; // reference to the parent node

// the parent is null for the root node

private Node(Node L, String d, Node r, Node p) {

left = L;

data = d;

right = r;

parent = p;

}

}

private Node root;

public BinaryTree() {

// create an empty tree

root = null;

}

public BinaryTree(String d) {

// create a tree with a single node

root = new Node(null, d, null, root);

}

public BinaryTree(BinaryTree b1, String d, BinaryTree b2) {

// merge the trees b1 AND b2 with a common root with data d

root = new Node(null, d, null, root); // creating new Node

root.left = b1.root;

root.right = b2.root;

b1.root.parent = root;

b2.root.parent = root;

}

public BinaryTree(String t, String open, String close, String empty) {

/*

* create a binary tree from the in order format discussed in class. Assume t is

* a syntactically correct string representation of the tree. Open and close are

* the strings which represent the beginning and end markers of a tree. Empty

* represents an empty tree. The example in class used ( ) and ! for open, close

* and empty respectively. The data in the tree will not include strings

* matching open, close or empty. All tokens (data, open, close and empty) will

* be separated By white space Most of the work should be done in a private

* recursive method

*/

}

}

Need some help for this method which is public BinaryTree(String t, String

Stri open The tee wil be

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!