This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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,
[Andrew: put code between [code] and [/code] UBB tags] [ June 21, 2006: Message edited by: Andrew Monkhouse ]
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
Joined: Jun 21, 2006
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?
Joined: Oct 13, 2005
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.
Joined: Oct 13, 2005
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.