I need to construct a binary tree, but I get
java.lang.OutOfMemoryError: Java heap space exception. In other words I have memory leak in my code.
What I want, is to contruct a binary tree of array values, so that right child has the array values and left has zero values. So if array looks like that:
data[0][0]=2
data[0][1]=3
data[1][0]=1
data[1][1]=4
- the tree should look like this:
How I have done this is so that I made a Tree class:
And I have the main class where I construct the tree with the following methods:
This works when the length of my array is 10 for example, but when I try with data[100][2] - array that has a length of 100, I get the
java.lang.OutOfMemoryError: Java heap space exception.
So how should I solve my problem, what am I doing wrong?
I have heard one solution that the tree should be presented as (int) array - not as the big tree structure object. Is this the most normal way or can I fix my solution, because I like it (OO kind of thinking) more
thanx
[ October 18, 2005: Message edited by: Juhan Voolaid ]
[ October 18, 2005: Message edited by: Juhan Voolaid ]
[ October 18, 2005: Message edited by: Juhan Voolaid ]
[ October 19, 2005: Message edited by: Juhan Voolaid ]
[ October 19, 2005: Message edited by: Juhan Voolaid ]