Re: infinite recursion
On Thu, 11 Oct 2007 10:30:23 -0700, andreyvul <andrey.vul@gmail.com>
wrote:
This method is supposed to return an array of shorts which represent
all of the possibilities for a given sudoku square (where each value
is a not-masked bitset with element + 1 equalling position). So far,
it gets stuck in an infinite recursion. Where is the inifinite
recursion in this method and how do I fix it?
short[] allOptions(short val) {
Vector<Short> cc = new Vector<Short>(0);
Iterator<Short> it;
short[] rv;
//check which numbers are available
short i;
for (i = 0; i < 9; ++i)
//bitmask check (1 == unavailable, 0 == available)
if (((1 << i) & val) == 0)
//available, add number to cc
cc.add(cc.size(), (short)(i + 1));
//create return array
rv = new short[cc.size()];
it = cc.iterator();
i = 0;
while (it.hasNext())
rv[i++] = it.next();
return rv;
}
I put this into a small test harness and it worked fine, terminating
as expected. I suspect that your problem is in the code that calls
this function.
rossum