Need help with my program it wants : Import bridges.connect.Bridges to allow you
ID: 3686234 • Letter: N
Question
Need help with my program it wants :
Import bridges.connect.Bridges to allow you to create a Bridges object
- Initialize a Bridges object with this assignment number, your username, and your API key. (See the Bridges template on Moodle for details)
- The driver will remain essentially the same as the provided skeleton code
- Call Bridges’ setDataStructure method passing in the root of your tree and then call Bridges’ visualize method
This is my driver :
import bridges.connect.Bridges;
public class TreeDriver {
private static final String API_Key = "805130419849";
private static final String USERNAME = "names";
Bridges bridge = new Bridges(0, API_Key, USERNAME);
public static void main(String[] args) {
BST<Integer, Integer> tree = new BST<Integer, Integer>();
Integer[] values = {50, 25, 75, 50, 13, 17, 15, 37, 100, 22, 110, 60};
for(Integer v : values) {
tree.insert(v, v);
}
System.out.println(" Preorder:");
tree.preorder();
System.out.println(" Postorder:");
tree.postorder();
System.out.println(" Inorder:");
tree.inorder();
System.out.print(" count leaf nodes ");
if( tree.countLeaves() == 5 ) {
System.out.println(":)");
} else {
System.out.println(":(");
}
System.out.print("count internal nodes ");
if( tree.countInternalNodes() == 7 ) {
System.out.println(":)");
} else {
System.out.println(":(");
}
System.out.print("count two-child nodes ");
if( tree.countTwoChildNodes() == 4 ) {
System.out.println(":)");
} else {
System.out.println(":(");
}
System.out.print("max path length ");
if( tree.getMaxPathLength() == 4 ) {
System.out.println(":)");
} else {
System.out.println(":(");
}
}
}
Explanation / Answer
Here is the updated driver code for you, with your specified requirements, as comment. If you find any difficulty with this, post it along with the bridges package.
import bridges.connect.Bridges;
public class TreeDriver {
private static final String API_Key = "805130419849";
private static final String USERNAME = "names";
//Initialize a Bridges object with this assignment number, your username, and your API key.
Bridges bridge = new Bridges(0, API_Key, USERNAME);
public static void main(String[] args) {
BST<Integer, Integer> tree = new BST<Integer, Integer>();
Integer[] values = {50, 25, 75, 50, 13, 17, 15, 37, 100, 22, 110, 60};
for(Integer v : values) {
tree.insert(v, v);
}
System.out.println(" Preorder:");
tree.preorder();
System.out.println(" Postorder:");
tree.postorder();
System.out.println(" Inorder:");
tree.inorder();
System.out.print(" count leaf nodes ");
if( tree.countLeaves() == 5 ) {
System.out.println(":)");
} else {
System.out.println(":(");
}
System.out.print("count internal nodes ");
if( tree.countInternalNodes() == 7 ) {
System.out.println(":)");
} else {
System.out.println(":(");
}
System.out.print("count two-child nodes ");
if( tree.countTwoChildNodes() == 4 ) {
System.out.println(":)");
} else {
System.out.println(":(");
}
System.out.print("max path length ");
if( tree.getMaxPathLength() == 4 ) {
System.out.println(":)");
} else {
System.out.println(":(");
}
//Call Bridges’ setDataStructure method passing in the root of your tree
bridge.setDataStructure(tree);
//Call Bridges’ visualize method
bridge.visualize();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.