java - Entirety of stack being set to one value -


I have a problem problem I'm programming for Android and I try to get a set of integer sets I am doing I have written the code to generate the code, and I track it with a remote debugger and it is working properly, it works by putting each new combo into the stack. However, each combo in the stack is being updated with every change in the active array, which has been repeatedly committed to the heap in many forms. I believe that this problem relates to my new combo containing pointers for the original array at the time of the construction of the combo. However, I'm not sure how to fix the problem.

All advice is appreciated, and thanks for your time.

  / ** * * @ The ultimate combo sysyes * We are finding the desired size of the combo * @ Ultimate Value * Dataset; Ints * should be an array in which all possible combinations of comboSize for size * / private combo [] getCombos (Int comboSize, int [] value) {stack & lt; Combo & gt; Combo = new stack & lt; Combo & gt; (); // combos.ensureCapacity (int) Math.pow (values.length, comboSize) + 1); GetIntArrayZeroToTarget (values.length - 1); Int [] temp = getIntArrayZeroToTarget (comboSize-1); // System.arraycopy (surrogates, 0, temp, 0, comboSize); Combos.push (new combo (temporary)); // Init work index = comboSize-1; // Bad things are hidden in this code, with it dry for two days during mortal war. I surrendered. Switch (combos) {for case 2: (for int i = 0; i & lt; values.length; i ++) {for (int j = i + 1; j & lt; values.length; j ++ ) {Temp [0] = i; Temporary [1] = j; Combos.push (new combo (temporary)); } } break; For case 3: (int i = 0; i  

You are saying that your issue refers to the same array from the Combo objects . To fix this, you just assign a new array before each combo object. So in each interior of the loop of the switch statement, place this line first:

  temp = new int [comboSize];   

This should fix your problem. (Alternatively, you can create a new array of combo's default constructor and make a copy of the array that was given in the new one.)

Therefore The problem is, but here are some suggestions:

First of all: To solve this problem, the "two-step" approach can be integrated into one if you have internal In the value [] the array refers to the loops of the switch statement A. For example, for the first loop, Case Change the respective lines under 2:

  temp [0] = value [i]; Temporary [1] = value [ja];   

Then press the combo. This eliminates the need to make "the second pass" going from the proxy-combos to the real people, and the third acombs end the requirement of a loop, which I believe you can return to the original order of the combo (because The second pass loop reverses it.)

Second: You can eliminate the need for a switch / case statement and duplication code using a recursive function. This is beyond the scope of the question, but it will also allow you to support the combination of any number, not just the hardcod (currently up to four) by you.

Comments