Need Help With a Brute Search

I need help with just getting something to display but I keep getting an error for comparison between pointer and integer. I'll post code below.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
void findPeaks(int board[][COLS], int rows)
{
    bool found;

    while(found = false){
        for(int j = 0; j < rows; j++)
        { for(int k = 0; k < COLS; k++){
            if(board[j][k] > board[j+1][k+1] && board[j] > board[j-1][k-1])
                found = true;
                cout << board[j][k] << "is a relative peak." << endl;
        }
        }
    }
}


It's in the if statement. I just need help getting it to display. I think I've got the searching correct.
Any help would be appreciated. Thanks.
1
2
3
4
5
6
7
8
9
10
11
12
bool findRelativePeak( const int board[][NUM_COLS], int num_rows )
{
    for( int row = 1 ; row < (num_rows-1); ++row ) // only inner rows (skip first and last row)
        for( int col = 1 ; col < (NUM_COLS-1); ++col ) // only inner cols
            if( board[row][col] > board[row+1][col+1] && board[row][col] > board[row-1][col-1] )
            {
                std::cout << board[row][col] << "is a relative peak.\n" ;
                return true;
            }

     return false ; // did not find a relative peak
}
Last edited on
&& board[j] > board[j-1][k-1]
Do you notice any differences between the first board and the second?

Also note that that second is accessing your arrays out of bounds the first time through the loop.

Topic archived. No new replies allowed.