4 queens backtracking in cpp
void nQueen(int row,int n){
//if all queens are placed
if(row>=n){
cout<<"Solution: ";
print_queens(n);
cout<<endl;
return;
}
for(int col=0;col<n;col++){
if (check(ar,row,col,n)){
ar[row][col]=1;
//to place next queen in the next row
nQueen(row+1,n);
ar[row][col]=0; //backtrack
}else{
cout<<"Backtracking from node: ";
print_queens(n);
cout<<col+1<<endl;
}
}
}