Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Tree creation problem

 
V.Sudhakar reddy Ch
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 50251
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 50251
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 50251
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65227
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic