User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 426,905 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,309 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 1673 | Replies: 3
Reply
Join Date: Jan 2005
Posts: 55
Reputation: kharri5 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
kharri5's Avatar
kharri5 kharri5 is offline Offline
Junior Poster in Training

Help Someone help me hate trees less

  #1  
Feb 2nd, 2005
I have a few problems.

I want to read in a .dat file with characters like below:

A B C
B * D
D * J
J * *

i used a readLine() from a fileReader, and put all of the characters into a char array.

Then i want to take each character and put it on a stack, but the stack I have to build from scratch, and can only accept Objects. I have no idea how to make chars Objects, because they are inconvertible type.

Secondly I have to put all of these chars into a tree, and print out the tree in proper order. A being parent/root B left child, C right child, and then B's left child is null because of the asterisk, and B's right child is D and so on until J which has no children and its done. I have no idea how to make a tree. I want to make a class Tree, but i don't know what methods to put, I don't know what to do first, I dont know I DONT KNOOOW! and its killing me being so stuck. If anyone knows how to solve any of my problems it would help me immensly, because I'm dying slowly and painfully from this dumb program.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,752
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 18
Solved Threads: 199
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Someone help me hate trees less

  #2  
Feb 2nd, 2005
There is a wrapper class Character which can be used to store chars as Objects.
This is equivalent to classes like Integer, Boolean, and Double (among others).
If you're using 1.5 (Tiger, 5.0) that wrapping will be taken care of for you.

If you use the correct Tree from the collections API your sorting will be done for you and all you'll need to do is create an Iterator over the tree (which the Tree can give you) and iterate over that.

The API docs should help you find and use the classes you want.
I find it highly instructive to once in a while just sit back for an hour or so and browse through it. Despite having used Java professionally and fulltime since 1999 I still find things in there I never knew existed.
Reply With Quote  
Join Date: Jan 2005
Posts: 55
Reputation: kharri5 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
kharri5's Avatar
kharri5 kharri5 is offline Offline
Junior Poster in Training

Re: Someone help me hate trees less

  #3  
Feb 3rd, 2005
thanks for the hint on Character class...niiice....but the Tree i have to construct from scratch. can't use predifined stuff for it. I have no idea how to set up the tree class, and what methods it should have...the API has confused me more I think.
Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,752
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 18
Solved Threads: 199
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Someone help me hate trees less

  #4  
Feb 3rd, 2005
Check out any decent book on data structures, all should have information on defining trees and iterating over them.

You may also look at the sourcecode for java.util.TreeMap or java.util.TreeSet and take inspiration from there.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Java Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Java Forum

All times are GMT -4. The time now is 11:16 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC