示例#1
0
int leaf_count(Node node){
	if(!node)
		return 0;
	else if(is_leaf(node))
		return 1;
	else return(leaf_count(node->left) + leaf_count(node->right));
}
示例#2
0
int test_leaf_count()
{
	const char *test_name = "test_leaf_count";
	struct rooted_tree tree = tree_3();	/* ((A:1,B:1.0)f:2.0,(C:1,(D:1,E:1)g:2)h:3)i; */

	if (leaf_count(&tree) != 5) {
		printf ("%s: leaf count should be 5, not %d\n", test_name,
				leaf_count(&tree));
		return 1;
	}

	printf ("%s: ok.\n", test_name);
	return 0;
}
示例#3
0
文件: display.c 项目: gatoravi/MFAST
int main(int argc, char *argv[])
{
	struct rooted_tree *tree;
	struct parameters params;
	int align_leaves;
	int with_scale_bar;
	enum display_status status; 
	void (*node_destroyer)(struct rnode *) = NULL;

	params = get_params(argc, argv);

	if (params.svg) {
		set_svg_parameters(params);
		if(! svg_init()) {
			fprintf (stderr, "%s\n", get_last_error_message());
			exit(EXIT_FAILURE);
		}
		node_destroyer = destroy_svg_node_data;
	}

	while (NULL != (tree = parse_tree())) {
		align_leaves = is_cladogram(tree);
		/* show scale bar IFF tree is NOT a cladogram. Since
		 * is_cladogram() takes some time to run, we just look
		 * up  'align_leaves' which has the same value. */
		with_scale_bar = !align_leaves;
		/* User can also suppress scale bar */
		if (params.no_scale_bar) with_scale_bar = FALSE;

		if (params.svg) {
			svg_header(leaf_count(tree), with_scale_bar);
			svg_run_params_comment(argc, argv);
			status = display_svg_tree(tree,
					align_leaves, with_scale_bar,
					params.branch_length_unit);
			switch(status) {
				case DISPLAY_OK:
					break;
					assert(0);
				case DISPLAY_MEM_ERROR:
					perror(NULL);
					exit(EXIT_FAILURE);
				/* The following two should never happen */
				case DISPLAY_UNKNOWN_STYLE:
				default:
					assert(0);
			}
			svg_footer();
		} else {
			prettify_labels(tree);
			status = display_tree(tree, params.width,
					align_leaves,
					params.inner_label_pos,
					with_scale_bar,
					params.branch_length_unit,
					params.scale_zero_at_root);
			switch(status) {
				case DISPLAY_OK:
					break;
					assert(0);
				case DISPLAY_MEM_ERROR:
					perror(NULL);
					exit(EXIT_FAILURE);
				/* The following two should never happen */
				case DISPLAY_UNKNOWN_STYLE:
				default:
					assert(0);
			}
		}
		destroy_tree_cb(tree, node_destroyer);
	}

	return 0;
}