import java.util.LinkedList; public class IntTree { private Node root; private static class Node { public int key; public Node left, right; public Node(int key) { this.key = key; } } public void printInOrder() { printInOrder(root); } private void printInOrder(Node n) { if (n == null) return; printInOrder(n.left); System.out.println(n.key); printInOrder(n.right); } /* * Returns the number of nodes with odd keys. For example, the BST with level * order traversal 50 25 100 12 37 150 127 should return 3 (25, 37, and 127). */ public int sizeOdd() { // TODO throw new RuntimeException
import java.util.LinkedList;
public class IntTree {
private Node root;
private static class Node {
public int key;
public Node left, right;
public Node(int key) {
this.key = key;
}
}
public void printInOrder() {
printInOrder(root);
}
private void printInOrder(Node n) {
if (n == null)
return;
printInOrder(n.left);
System.out.println(n.key);
printInOrder(n.right);
}
/*
* Returns the number of nodes with odd keys. For example, the BST with level
* order traversal 50 25 100 12 37 150 127 should return 3 (25, 37, and 127).
*/
public int sizeOdd() {
// TODO
throw new RuntimeException("Not implemented");
}
Step by step
Solved in 3 steps with 1 images