开发者

Proper data structure to represent a Sudoku puzzle? i.e it should use less memory compared to other data structure used?

Please suggest the solution for the qn? Proper data structure to represent a Sudoku puzzle? i.e. it should use less memory compared to other data struct开发者_开发知识库ure used?


Least amount of memory*:

byte puzzle[41];

GET_PUZZLE(x,y) = puzzle[(9*y+x)/2] >> ((9*y+x)%2 * 4) & 0x0F;

Each number box is stored in 4 bits - so two numbers per byte.

*Measuring data structure only; not the program memory/etc taken up by the large inefficient GET_PUZZLE().


Ease of use, maintainability, speed, etc:

byte puzzle[9][9];

GET_PUZZLE(x,y) = puzzle[x][y]

What any sane person would use. Fortunately, it's the most obvious, too.


How about byte[81] or byte[9][9]

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜