I am fairly new to c++ and prcticing some ds algo problem. From last 24 hours, I have been stuck with this.
/*Find shortest distance of every cell from landmine in a maze*/
#include <iostream>
#include <algorithm>
#include <queue>
#include <climits>
struct cell{
int x, y;
};
const int M = 6, N = 5;
int row[4] = {-1, 0, 1, 0};
int col[4] = {0, -1, 0, 1};
bool isValidandSafeObject(int x, int y, char mat[][N], int minDist[][N]){
if ((x >= 0 && x < M) && (y >= 0 && y < N) ){
if (mat[x][y] == "O") && (minDist[x][y] == -1){
return true;
}
}
return false;
}
int[][N] updateDistance( char field[][N]){
int minDist[M][N];
queue<cell> Q;
for (int i = 0; i < M ; i++){
for ( int j = 0; j < N; j++){
if (field[i][j] == "M"){
Q.push({i, j})
minDist[i][j] = 0;
}
else{
minDist[i][j] = -1;
}
}
}
while (!Q.empty()){
int x = Q.front().x;
int y = Q.front().y;
Q.pop();
for( int k = 0; k < 4; k++){
i = x + row[k];
j = y + col[k];
if isValidandSafeObject( i, j, field, minDist){
Q.push({i, j});
minDist[i][j] += 1;
}
}
}
return minDist;
}
void main(){
char mat[][N] =
{
{'O', 'M', 'O', 'O', 'X'},
{'O', 'X', 'X', 'O', 'M'},
{'O', 'O', 'O', 'O', 'O'},
{'O', 'X', 'X', 'X', 'O'},
{'O', 'O', 'M', 'O', 'O'},
{'O', 'X', 'X', 'M', 'O'}
};
int minDist[M][N];
for (int i = 0; i < M; i++)
{
for (int j = 0; j < N; j++)
std::cout << std::setw(5) << updateDistance(mat);;
std::cout << '\n';
}
}
At line 20, if (mat[x][y] == "O") && (minDist[x][y] == -1){
I am getting the error ISO C++ forbids comparison between pointer and integer [-fpermissive]
. I have searched stackoverflow, but none of the existing problems and solutions, seem to satisfy my problem.
I am using CodeBlocks. It would be very helpful, If someone could help me.