내 코드 함수에서 3D 배열을 3D std :: vector로 바꿨고 무한 루프를 입력했습니다. 힌트를 주시겠습니까? 대신 벡터를 사용해야합니다. array.Thanks :
내 최초의 코드이었다 :3D 배열을 3D std :: vector
//arr is a 3D array of a sudoku table,the 3 rd dimension is for keeping values 0 to 13
//for a cell, and when I assign values I start from index 1 to 12
bool sol(int arr[12][12][13]) {
int row,col;
if(!find_empty(arr,row,col)) return true;
for(int i=1;i< 12;i++) { //for digits 1 to 12
if(is_working(arr,row,col,arr[row][col][i])) { //if i can put the value in a cell
arr[row][col][0] = arr[row][col][i]; //replace the first element for a cell with that value
//here I want to use vector because I want to use an ac3 algorithm
//and remove those values that not satisfy constraints and shrink domain size having less values to verify with backtrack
if(sol(arr)) return true;
arr[row][col][0] = 0;
}
}
return false;//if not backtrack
}
내가 함께 ARR 을 바꿉니다!
std::vector<std::vector<std::vector<int> > > vec;
vec.resize(12);
for(int i=0;i<12;i++)
{
vec[i].resize(12);
for(int j=0;j<12;j++)
{
vec[i][j].resize(13);
for(int k=0;k<13;k++)
vec[i][j][k]=table[i][j][k];
}
}
bool sol(std::vector<std::vector<std::vector<int> > >& vec) {
int row,col;
if(!find_empty(vec,row,col)) return true;
for(int i=1;i< vec[row][col].size();i++) {//for remainig values in domain
if(is_working(vec,row,col,vec[row][col][i])) {//same as above but having less values to verify for
vec[row][col][0] = vec[row][col][i];
if(sol(vec)) return true;
vec[row][col][0] = 0;
}
}
return false;
}
와 지금은 무한 루프를 입력 년대 초기 코드는 오류가 없다, 그것은이다 간단한 backtracking.The 문제가 나타납니다 내가 VEC .Could와 ARR 를 교체 한 후 당신은 내게
* "무한 컴파일시에 반복하라 "* ehmmm 이것으로 무엇을 의미합니까? – Manu343726
루프를 인덱스 '1'로 시작 하시겠습니까? –
'vector :: resize'는 요소를 삽입하거나 지워서 벡터의 실제 내용을 변경합니다. – P0W