Re: Print a binary search tree
kaltizer wrote:
...
Please forgive the mistakes in my posting format.
Please forgive anything I said, that made you feel you
owed me an apology. It was simply technical advice.
( Or another way to put that might be..
"I'll forgive you - if you'll forgive me" ;)
For the record, there were no 'mistakes' in your post, I was
just suggesting things that might help get other people 'up
and running' with the problem - faster and more easily.
...I will look into
the information for posting code before I post again.
That is a good strategy! Not everyone sees the benefit
of preparing an SSCCE, but I am hoping you will.
..I did copy/
paste the code into Notepad, which I thought would remove all
formatting. Obviously,I was wrong about that!
Yep. Notepad will retain 'tabs'.
Now, about the problem at hand. I was using the out.print() in hopes
of calling my internal print() method. It prints to the console just
fine, and I had used it before for printing lists, queues, and stacks
to a text file. But, I see what you are saying about the the
PrintWriter class. I just have to figure out a way to get the tree
into one of those methods.
There are a number of options for print()ing. All of them
expect some data.
...That's what I'm having problems
understanding about trees. I don't have a tree object to perform one
of the PrintWriter methods on. I guess I need to create a method
along with a binary tree object, and then insert each node into this
tree instance, then call one of the PrintWriter methods to be
performed on this object. Does that sound like a good plan?
..hmm. I am probably not the best one to answer that
question.
(Having said that..)
I would probably implement a 'toString()' method on the
'tree structure' being created, and print(theTreeObject).
But I think Roedy has already covered that 'toString()'
aspect better than I could.
Certainly, creating 'an object' that represents this tree
structure would be the way *I'd* go, but I am no 'design guru',
so I will cede to the advice of others - who are.
--
Andrew Thompson
http://www.athompson.info/andrew/
Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-setup/200710/1