aspose file tools*
The moose likes Java in General and the fly likes Tree creation problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Tree creation problem" Watch "Tree creation problem" New topic
Author

Tree creation problem

V.Sudhakar reddy Ch
Greenhorn

Joined: Jun 21, 2006
Posts: 2
hi,
I have written folowing code for tree creation. Iam using this tree in my application. I have used inner class Tnode for a node in tree. This code create tree hierarchically depending on the input strings. Each node contains 4 parts(string, float[][],two objects which store addresses of successor and child nodes). When i create nodes using inner class, the float array (Measures)of the individual nodes contains same values for all nodes.
For example, in the following code first node is created with Measures array contains all 1's, second node is created with Measures array contains all 2's, third node is created with Measures array contains all 4's. When i print the tree with content of Measures array, it was printing 4 as contents of Measures for all nodes of tree. Why it was not printed Measures contents differently(1's, 2's and 4's) as output of nodes? What changes are needed to print in this way? can any one help me soving this problem?

Thanks in advance,

by
sudhakar



[Andrew: put code between [code] and [/code] UBB tags]
[ June 21, 2006: Message edited by: Andrew Monkhouse ]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38910
    
  23
Welcome to the Ranch.

The result is printing exactly as you have told it to. You print out all 4s because you have only 4s in your arrays. If you want to print out 1, you will have to put your print instruction earlier.
V.Sudhakar reddy Ch
Greenhorn

Joined: Jun 21, 2006
Posts: 2
hi,
> You print out all 4s because you have only 4s in your arrays. If you
> want to print out 1, you will have to put your print instruction earlier.
-------------------------------------------------------------------------
The first two measures arrays of nodes are intialized with 1's and 2's.
why it was printed only 4's for all Measures arrays of nodes? I think three
arrays overriding with latest value of array(4's). But i need this 1's and 2's in those arrays. what part of code i need to change to stay 1's and 2's?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38910
    
  23
Yes, you have set all your nodes to read 4.

Look at your code:-You have written down quite correctly what happens. You get all 1s, then you get all 2s, then you get all 4s. That seems to be what your program does; I fail to see what that has to do with trees, however.

If you want to see 1s or 2s, all you need to do is repeat the T.print() statement.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38910
    
  23
You are inserting an array into your nodes, then doubling it. Then you repeat the insertion and double the array. You don't actually seem to do anything with the nodes.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61241
    
  66

"V.Sudhakar reddy Ch",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Tree creation problem