C Board  

Go Back   C Board > General Programming Boards > FAQ Board

 
 
LinkBack Thread Tools Display Modes
Old 10-31-2001, 12:21 PM   #1
Unregistered
Guest
 
Posts: n/a
Question Printing a binary tree??

I am currently working on a function that accepts the root for a binary tree and prints out the tree structure with the numbers. I want to know where do I begin. Do I need to count the height of the tree or what... I need some help....
 
Old 10-31-2001, 12:39 PM   #2
and the hat of vanishing
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,214
> I want to know where do I begin.
At the root of the tree

> Do I need to count the height of the tree or what
That would depend on how you choose to represent the tree when you've printed it.

If its just a text dump, no formatting is required

But if it's a nice graphical thing, then more work is required.
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Up to 8Mb PlusNet broadband from only £5.99 a month!
Salem is offline  
Old 10-31-2001, 12:43 PM   #3
Unregistered
Guest
 
Posts: n/a
I want a graphically output:
example:
100
50
40
25 30
12
......and such
 
Old 10-31-2001, 12:45 PM   #4
Unregistered
Guest
 
Posts: n/a
that didnt come out right....cuz I guess this forum doesnt display the spaces. I want a graphically tree with the corresponding numbers.
 
Old 10-31-2001, 04:31 PM   #5
Unregistered
Guest
 
Posts: n/a
Question

i still need some help???what this printing of a tree structure.....
 
Old 10-31-2001, 07:35 PM   #6
Registered User
 
Join Date: Sep 2001
Posts: 752
Still not too sure what your asking, but here goes...

1) The generic treeprinting program
Code:
void printtree(node * tree)
{
 if (tree != NULL)
 {
  print (tree -> info); // Not a real command
  printtree (tree -> left);
  printtree (tree -> right);
 }
}
2) If you want a graphical tree, might I suggest something using ASCII characters 179, 192, and 195? You know, just do those to draw lines from nodes to their children, with each node being on a different line. It's not spaced out as a tree diagram usually is, but it does have connectivity lines, which is the importatnt thing, personally.
__________________
Callou collei we'll code the way
Of prime numbers and pings!
QuestionC is offline  
 

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
determine if tree is strictly binary bst ashir30000 C++ Programming 1 05-20-2009 02:27 AM
Binary Search Tree - one last question tms43 C++ Programming 2 11-14-2006 03:58 AM
Binary Search Trees Part III Prelude A Brief History of Cprogramming.com 16 10-02-2004 03:00 PM
Tutorial review Prelude A Brief History of Cprogramming.com 11 03-22-2004 09:40 PM
Binary Tree Search C++Newbie C++ Programming 5 03-22-2002 12:38 PM


All times are GMT -6. The time now is 02:53 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22