/** * Builds an N-ary tree that contains character keys in the given range. * * @param integer lo The lower bound of the range. * @param integer hi The upper bound of the range. * @return An N-ary tree. */ public static function buildTree($lo, $hi) { $mid = intval(($lo + $hi) / 2); $result = new NaryTree(2, box(chr($mid))); if ($lo < $mid) { $result->attachSubtree(0, self::buildTree($lo, $mid - 1)); } if ($hi > $mid) { $result->attachSubtree(1, self::buildTree($mid + 1, $hi)); } return $result; }
/** * Main program. * * @param array $args Command-line arguments. * @return integer Zero on succes; non-zero on failure. */ public static function main($args) { printf("Demonstration program number 5.\n"); $status = 0; GeneralTree::main($args); BinaryTree::main($args); NaryTree::main($args); BinarySearchTree::main($args); AVLTree::main($args); MWayTree::main($args); BTree::main($args); return $status; }
/** * Main program. * * @param array $args Command-line arguments. * @return integer Zero on success; non-zero on failure. */ public static function main($args) { printf("NaryTree main program.\n"); $status = 0; $nt = new NaryTree(3, box(1)); $nt->attachSubtree(0, new NaryTree(3, box(2))); $nt->attachSubtree(1, new NaryTree(3, box(3))); $nt->attachSubtree(2, new NaryTree(3, box(4))); AbstractTree::test($nt); return $status; }