hw4 - #include #include #include #include #include #...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#include <string> #include <cstring> #include <queue> #include <cstdlib> #include <climits> # using namespace std; u class Sudoku { public: Sudoku(){generate();} ~Sudoku(){}; ~ bool isValueValid(int row, int col, int value) { int startCol, startRow; for(int i = 0; i < 4; i++) if(matrix[i][col] == value) return false; //check for same value in column for(int i = 0; i < 4; i++) if(matrix[row][i] == value) return false; //check for same value in row startCol = col - col%2; startRow = row - row%2; for(int i = 0; i < 2; i++) for(int j = 0; j < 2; j++) if(matrix[startRow + i][startCol + j] == value) return false; //check inside the minigrid return true; } string possibleValues(int row, int col) //returns the possible values for a cell { string posVal = "1234"; int startCol, startRow; char buffer[33]; string::size_type pos; for(int i = 0; i < 4; i++) //check within a column for unassigned values if(matrix[i][col] != 0) { _itoa_s(matrix[i][col], buffer, 33, 10); if((pos = posVal.find(buffer, 0)) < 4) posVal.erase(pos, 1); } for(int i = 0; i < 4; i++) //check within a row for unassigned values if(matrix[row][i] != 0) { _itoa_s(matrix[row][i], buffer, 33, 10); if((pos = posVal.find(buffer, 0)) < 4) posVal.erase(pos, 1); } startCol = col - col%2; startRow = row - row%2;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/24/2010 for the course COS 221 taught by Professor Christozov during the Spring '10 term at American University in Bulgaria.

Page1 / 5

hw4 - #include #include #include #include #include #...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online