Пытаясь создать граф матриц после изменения одной вершины матрицы, я добавляю их в граф.Вот код для этого.
explicit Node(const State &head) : head(head) {
this->no_of_child = 0;
}
void AddChild(const State &state){
Node new_node(state);
children.push_back(new_node);
no_of_child = children.size();
}
void NextStates (){
int n = head.getN();
int ** matrix = head.getMatrix();
//For all empty places in matrix create a new node if it meets the constraints.
//Then add that node to the graph.
for(int i = 0 ; i < n ; i++) {
for (int j = 0; j < n; j++) {
if(matrix[i][j] == 0){
matrix[i][j] = 2;
State child(n, matrix, head.getRows(), head.getCols());
if(child.isLegal()){
AddChild(child);
cout<<"========================================="<<endl;
children[no_of_child-1].getHead().printState();
}
matrix[i][j] = 0;
}
}
}
cout<<"=========================================\n"
"========================================="<<endl;
for(int i = 0 ; i < no_of_child ; i++) {
children[i].getHead().printState();
cout<<"========================================="<<endl;
}
}
Сначала printState()
печатает именно то, что я хочу.Но после окончания цикла вторая printState()
печатает матрицу, но ничего не изменилось.Сначала я вижу, что это изменилось, но потом это просто копия моей исходной матрицы.Я даже не мог комментировать это.Пожалуйста, помогите.