//Free all the nodes of the given tree
void free_ascii_tree(asciinode *node) 
{
  if (node == NULL) return;
  free_ascii_tree(node->left);
  free_ascii_tree(node->right);
  free(node);
}
Exemplo n.º 2
0
//---------------------------------------------------------
//Free all the nodes of the given tree
void AsciiTree::free_ascii_tree(AsciiNode* ascii_node) 
{
	if(ascii_node==NULL)
		return;

	free_ascii_tree(ascii_node->left);
	free_ascii_tree(ascii_node->right);

	delete ascii_node;
}
Exemplo n.º 3
0
//---------------------------------------------------------
//prints ascii tree for given Node structure
void AsciiTree::print_ascii_tree() 
{
	if(_node==NULL)
	       return;

	AsciiNode* ascii_root=build_ascii_tree(_node);
	compute_edge_lengths(ascii_root);
	for(int i=0; i<ascii_root->height && i<MAX_HEIGHT; ++i) 
		lprofile[i]=INFINITY;
	compute_lprofile(ascii_root, 0, 0);
	int xmin=0;
	for(int i=0; i<ascii_root->height && i<MAX_HEIGHT; ++i) 
		xmin=std::min(xmin, lprofile[i]);
	for(int i=0; i<ascii_root->height; ++i) 
	{
		print_next=0;
		print_level(ascii_root, -xmin, i);
		std::cout<<std::endl;
	}
	if(ascii_root->height>=MAX_HEIGHT) 
		std::cout<<"(This tree is taller than "<<MAX_HEIGHT<<", and may be drawn incorrectly.)"<<std::endl; 
	free_ascii_tree(ascii_root); 
}