/** * Count the number of non-leaf descendant nodes */ public int getNumDescendants() { if (isLeaf()) return 0; int count = 0; if (! getLeftChild().isLeaf()) count += 1 + getLeftChild().getNumDescendants(); if (! getRightChild().isLeaf()) count += 1 + getRightChild().getNumDescendants(); return count; }
/** * Count the number of non-leaf descendant nodes */ public int getNumDescendants() { if (isLeaf()) return 0; int count = 0; if (! getLeftChild().isLeaf()) count += 1 + getLeftChild().getNumDescendants(); if (! getRightChild().isLeaf()) count += 1 + getRightChild().getNumDescendants(); return count; }
/** * Count the number of non-leaf descendant nodes */ public int getNumDescendants() { if (isLeaf()) return 0; int count = 0; if (! getLeftChild().isLeaf()) count += 1 + getLeftChild().getNumDescendants(); if (! getRightChild().isLeaf()) count += 1 + getRightChild().getNumDescendants(); return count; }
/** * @return the total number of nodes in this tree */ public int getSize() { Node root = getRoot(); if (root == null) return 0; return 1+root.getNumDescendants(); }
/** * @return the total number of nodes in this tree */ public int getSize() { Node root = getRoot(); if (root == null) return 0; return 1+root.getNumDescendants(); }
/** * @return the total number of nodes in this tree */ public int getSize() { Node root = getRoot(); if (root == null) return 0; return 1+root.getNumDescendants(); }