zijiaw / sudoku Goto Github PK
View Code? Open in Web Editor NEWA personal project for Software Engineering.
A personal project for Software Engineering.
void SudokuOutput(char *ret, int maxnum, char *ret2);
中的 ret ,ret2
建议改成 from,to 或者 src,dst 这样的名字 另外这个函数的名字不大很适合其功能,可以试试用Format这样的词来取名
char *result = new char[1000000 * 81 + 1];
char *q = new char[1000000 * (81 * 2 + 1)];
a. 使用了写死的容量大小,可以改成常量表示
b. 作为全局缓冲的数组可以写成静态而不是动态的
c. 建议注释说明空间这样计算的意义
class SudokuSolve {
public:
bool Solve(int r, int l);//递归填数
bool check(int r, int l, int num);//测试同行同宫同列是否已有num
void ProblemInit(int p[9][9]);//初始化
int(*getSolution())[9];//返回解
private:
int problem[9][9];
};
class SudokuMaker {
public:
bool fill(int r, int l, char *ret);//递归填数
bool check(int r, int l, int num);//判断在[r,l]处放入num是否符合数独规则
void RequestInit(int n);//初始化需求
private:
int maxnum;//需要生成的数独终局数
int count;//当前已生成的数独终局数
int M[9][9];//维护的数独棋盘
};
int(*SudokuSolver::getSolution())[9]
{
int(*p)[9] = new int[9][9];
for (int i = 0; i < 9; ++i)
{
for (int j = 0; j < 9; ++j)
{
p[i][j] = problem[i][j];
}
}
return p;
}
该函数申请的空间没有得到释放 建议在外部建立一个静态缓存 然后把这个缓存的指针传入这个函数中
vector<int(*)[9]> SudokuInput(char * filename)
{
ifstream file;
file.open(filename, ios::in);
int linenum = 0, curline = 0;
vector<int(*)[9]> ProblemSet;
int(*temp)[9] = new int[9][9];
if (!file.is_open())
{
cerr << "fail to open file!" << endl;
return ProblemSet;
}
while (!file.eof())
{
string buffer;
getline(file, buffer);
if (buffer.empty())
continue;
linenum++;
if (linenum % 9 == 1)
{
temp = new int[9][9];
curline = 0;
}
for (int i = 0; i < 9; ++i)
{
temp[curline][i] = buffer[2 * i] - '0';
}
curline++;
if (linenum % 9 == 0)
{
ProblemSet.push_back(temp);
temp = NULL;
}
}
file.close();
return ProblemSet;
}
这个容器内指针所得到的空间没有得到释放,建议在main方法尾部加以处理
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.