Link to home
Start Free TrialLog in
Avatar of David H.H.Lee
David H.H.LeeFlag for Malaysia

asked on

need assist to change the linked list of C++ into JAVA linked list

these questions is from a friend of mine, hope can get solutions from yours. Thanks

Questions:

1.i had declare an object of a class in my program, when i trying to execute it. it show me this error:
java.lang.StackOverflowError    
<<<< may i know what's the problem with this? by the way, the class which i declare an object with, is using Link-list data structure.is that problem with the link list ?

2 . the question
i'm trying to change the link- list of C++ into JAVA. the problem is, i'm not sure what should i do when it involve struct of C++ and pointer of the struct.

3. by the way, when we assign a null to an object in JAVA, which

(In C++)

Weight *next;

Weight(double w, Neuron sn)
{
    next = (Weight *)null;   //do i have to do the same in JAVA , which when i assign a null
                    //to the object, i will have to put cast of the class for it    
}


4. how to change this code?
(in C++)
Neuron *neuron1;
Neuron *neuronL;
Neuron *nptr;

neuron1=neuronL=nptr;  
(in JAVA, is it change to this? )
Neuron neuron1;
Neuron neuronL;
Neuron nptr;

neuron1=nptr;
neuronL=nptr;

5. sure can call the next object in the link list, when we do like this in JAVA or not ?
 >>  wi =wi.next;   ??

6. how to use the clone method? i mean in what case we should use this method?

7. there is somethings i wish to make sure of is:
>>  Network newNetwork; (In JAVA)
>>  Network *newNetwork; (in C++)

 or do we have to assign a null to each of the object which only declare and not yet been used?
>> Network newNetwork = null; (in JAVA) ?? or Network newNetwork = (Network) null ?????


i'm getting blur and blur already 8-}
i only left with 3 more days to submit the assignment ~.~
help~~~!!!
Avatar of bobbit31
bobbit31
Flag of United States of America image

2 . the question
i'm trying to change the link- list of C++ into JAVA. the problem is, i'm not sure what should i do when it involve struct of C++ and pointer of the struct.

Java has a built in LinkedList class in the SDK... look it up in the docs
3. by the way, when we assign a null to an object in JAVA, which

no.

Weight next;
next = null;
7.

Network newNetwork = null or
Network newNetwork = new newNetwork(...)
4.

Neuron neuron1 = New Neuron();
Neuron neuronL;
Neuron nptr;

neuron2 = neuron1;
nptr = neuron1;
the rest of them probably (i didn't read them too carefully) have something to do w/ the linked list you are using... try the java one and come back w/ any issues.
Avatar of David H.H.Lee

ASKER

yeap, the linked list of C++ involving Struct.
this is the error showed while my friend is trying to change compile his code
>>  java.lang.StackOverflowError
may i know the cause of this problem ?

this error occur when he is trying to declare an object for a class. the error capture using the exception handler is as above
Avatar of twobitadder
twobitadder

a stack trace and code list would be needed probably
a stack trace and code list ?
example ?
1.i had declare an object of a class in my program, when i trying to execute it. it show me this error:
java.lang.StackOverflowError    
<<<< may i know what's the problem with this? by the way, the class which i declare an object with, is using Link-list data structure.is that problem with the link list ?

it could be that the linked list implementation isn't deleting objects, simply flagging them as unavailable, this would eat up memory, check what happens on the remove method for each node if you can.
the fact that it's a stack overflow also points to the fact that all the node objects are still taking up memory since the references to the objects are stored on the stack whilst the fields making up the objects exist on the heap.
If you're creating a lot of nodes in your neural net maybe your system doesn't have enough memory.

you can set the default stack size with
 -Xss<size>        set java thread stack size

java -ss sizeofstack ClassA
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
the recursively call you mean . is it
>>>>   tryOnly = tryOnly.getNext();
??? by the way, if declaring an new object, which it will use at later.. do we have to assign null to that obejct?
assigning >>  objectTry = (Class)null;
??then later after we have finish using the object, is it compulsory for us to assign null to that object again ?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
24 neuron in input layer. 4 neuron in output layer and 50 neuron is hidden layer
ok, i try to check it  out . might need assists in further. thanks
That's a pretty small number of objects, i don't think that's the problem, unless you create new neurons to replace old ones and don't remove all pointers to the old neurons.  Then the GC wouldn't remove them.
I'd say your recursively calling a method, most probably in an endless loop.
The stack trace for the exception should point you to how it is occurring.

ex.printStackTrace();
by the way.. may i know where i can get information about Multilayer Perceptron, which is a Artificial Neural Network design.. i need help in setting the Input layer nodes, hidden layer nodes and output layer nodes.. and
how to solve the input scheme? if the data i got froom user is in "1" or "0" binary representation only....
and how about the output? in any numbers? or have to be same with the input we had set?

your helps will be appreciate...
thanks.