-2

the one that I like to see how it works graphically is this one

 public boolean splitArray(int[] nums) {
    int index = 0;
    int sum1 = 0;
    int sum2 = 0;

    return recallArray(nums, index, sum1, sum2);

}

public boolean recallArray(int[] nums, int index, int sum1, int sum2){
    if(index >= nums.length){
        return sum1 == sum2;
    }
        int value = nums[index];
        return recallArray(nums,index + 1, sum1 + value,sum2) 
        || recallArray(nums,index + 1, sum1 ,sum2 + value);
}

I try to use Jgrasp , that have a good visual debugger , but it only show me how the variables changes through the recursion calls, it is possible to Jgrasp to do the tree of recursion or something similar?, how?

Morgan Thrapp
  • 9,748
  • 3
  • 46
  • 67
Bodhert
  • 17
  • 1
  • 6
  • 1
    Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it. – CubeJockey Sep 02 '15 at 16:05
  • How about a stack trace? – bhspencer Sep 02 '15 at 16:07
  • The question is fine, IMO. I just edited the title to make it specifically about jGrasp. – HRJ Sep 07 '15 at 16:20

1 Answers1

0

You could do it yourself with a class (RACheck here) exploiting try-with-resources.

public boolean recallArray(int[] nums, int index, int sum1, int sum2) {
    try (new RACheck(nums, index, sum1, sum2)) {
        if (index >= nums.length) {
            return sum1 == sum2;
        }
        int value = nums[index];
        return recallArray(nums,index + 1, sum1 + value,sum2) 
            || recallArray(nums,index + 1, sum1 ,sum2 + value);
    }
}

class RACheck implements Autocloseable {
    static int recursionDepth;
    int myRecursionDepth;

    final int[] aliasToNums;
    final int[] copyOfNums;

    RAChec(int[] nums, int index, int sum1, int sum2) {
        myRecursionDepth = recursionDepth++;
        // copy initial values.
        this.aliasOfNums = nums;
        this.copyOfNums = Arrays.copyOf(nums, nums.length);
        // dump enter method
    }

    @Override
    public void close() {
        // dump leave method
        // highlight changes to nums
    }
}
Joop Eggen
  • 107,315
  • 7
  • 83
  • 138
  • Despite of syntax errors , the try method , when I declare try ( new RACheck...) throws me an ilegal start of type – Bodhert Sep 02 '15 at 16:32
  • Try-with-resources exists as of java 7, with java 6 one would need to write `RACheck c = new RACheck(...); try { ... } finally { c.close(); }` – Joop Eggen Sep 02 '15 at 16:46
  • this is what i tried so far, sorry, im begginer http://pastie.org/10392229 and still not working – Bodhert Sep 02 '15 at 16:53
  • In old java 6 no `try (c)`. And `finally` section needs to be added. The latter ensures that any return or exception still will call `c.close()`. – Joop Eggen Sep 02 '15 at 16:55