private void succ_next(int next) { int howMany = _result[next - 1].getHowMany(); GrayWord currentWord = _result[next - 1]; GrayWord nextWord = _result[next]; copyPreviousWord(next); if (howMany % 2 == 0) //liczba jedynek parzysta { nextWord.negate(0); } else //liczba jedynek nieparzysta { int z; if (currentWord.isEmpty()) { throw new Exception("trying to negate first 1 in empty sequence"); } else { z = currentWord.findFirst1(); } if (z + 1 >= n) { throw new Exception("z+1 > n"); } nextWord.negate(z + 1); } }
static void TestWord() { GrayWord gw = new GrayWord(); gw.zero(4); Debug.Assert(gw.isEmpty()); gw.negate(1); Debug.Assert(gw.ToString().Equals("0, 1, 0, 0")); Debug.Assert(gw.findFirst1() == 1); Debug.Assert(!gw.isEmpty()); Debug.Assert(gw.getHowMany() == 1); gw.negate(2); Debug.Assert(gw.getHowMany() == 2); }