Below is a function which counts for each character in a grid. I want to make this function return the counts for each character but I am stuck. Please, how can I improve the function below so that I can return each count which I require to process my other methods.
Thanks
int getNeighborhood(const char** grid, int N, int row, int col, int& bCount, int& fCount, int& rCount, int& gCount){
int currRow;
int currCol;
int countB = 0;
int countF = 0;
int countR = 0;
int countG = 0;
//loop through all 8 grids surrounding the current row and column.
for(int i = -1; i < 2; i++)
{
for(int j = -1; j < 2; j++){
currRow = row + i; //current row.
currCol = col + i; //current column.
if(currRow >= 0 && currRow < N && currCol >= 0 && currCol < N){
if(grid[row][col] == 'B')
{
++countB;
}
if(grid[row][col] == 'F')
{
++countF;
}
if(grid[row][col] == 'R')
{
++countR;
}
if(grid[row][col] == 'G')
{
++countG;
}
}
}
//return statement required
}
Aucun commentaire:
Enregistrer un commentaire