Java Recursion, calling it with Objects - How To Copy The Objects?

As you've identified, you're copying the reference not the list. You need to instantiate a new ArrayList object with the entries in the old list e. G List newList = new ArrayList(oldList) So this explicitly creates a new object containing references to the same elements Note as an aside that I pass around a reference to the interface List rather than the implementation - generally good practise since you're not exposing implementation throughout the codebase.

As you've identified, you're copying the reference, not the list. You need to instantiate a new ArrayList object with the entries in the old list. E.g.

List newList = new ArrayList(oldList); So this explicitly creates a new object containing references to the same elements. Note as an aside that I pass around a reference to the interface List rather than the implementation - generally good practise since you're not exposing implementation throughout the codebase.

ArrayList newP = P; This only creates a second reference to the same ArrayList. To copy the arraylist use ArrayList newP = new ArrayList(P).

OK some improvements based on answers comments but not really getting (the right way to put it) "what I think I want". Do check the initial post. – Recc Jul 3 '10 at 10:28.

The thing is that you are both using a counter (c) and the contents of the tempPX list (v). You use v to do the check but c as the assignment. The result is totally dependent on data ordering and doesn't produce anything meaningful.

Normally you'd use one or the other and use it both in the check and the assignment. If (p.isEmpty() && p.isEmpty()) { countr.size()++; } else { you = 0; c = 0; // find vertex with largest degree tempPX. AddAll(p); tempPX.

AddAll(x); // P U X for (Integer v : tempPX) { if (neighboursv.size() > neighboursu.size()) { you = c; } c++; } Either your goal is to find the index in the temppx list with the largest amount of neighbours (drop the c variable and the c++ line, use v in the assignment) OR to just find the index with the largest amount of neighbours without any restriction on the index, in that case you would use a for loop like this: for (int c = 0; c My guess is your trying to do the first case.

OK Fixed loop and obvious lame mistakes. How about the copying now? Copy first modify the copy, pass the copy, then r p x are those values, copy them, modify them pass those copies recursively, that's my logic.(neighborsnode contains the set of neighbors of node so the index in the loop is crucial) – Recc Jul 3 '10 at 13:31.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions