It touches an edge of the region, and is therefore not surrounded.

On Jun 12, 2:39 am, Nishant Pandey <nishant.bits.me...@gmail.com>
wrote:
> juat want to ask why the last region was not flipped from o to x?
>
>
>
>
>
>
>
> On Tue, Jun 11, 2013 at 11:57 PM, Don <dondod...@gmail.com> wrote:
> > // Flip a region including location (x,y) from "from" to "to".
> > // Returns true if region is surrounded.
> > bool flip(char board[][], int n, int x, int y, char from, char to)
> > {
> >    if ((x >= 0) && (y >= 0) && (x < n) && (y < n)) return false;
> >    if (board[x][y] != from) return true;
> >    board[x][y] = to;
> >    return flip(board,n,x-1,y) && flip(board,n,x+1,y) &&
> >             flip(board,n,x,y-1) && flip(board,n,x,y+1);
> > }
>
> > // Flips all regions of 'O' completely surrounded by 'X' to 'X'
> > void captureSurrounded(char board[][], int n, int x, int y)
> > {
> >     int x,y;
> >     for(x = 0; x < n; ++x)
> >        for(y = 0; y < n; ++y)
> >            if (flip(board,n,x,y,'O','v'))
> >                flip(board,n,x,y, 'v', 'X');
>
> >     // Set regions not surrounded back to 'O'
> >     for(x = 0; x < n; ++x)
> >        for(y = 0; y < n; ++y)
> >            if (board[x][y] == 'v') board[x][y] = 'O';
> > }
>
> > On Jun 11, 3:05 am, Jai Shri Ram <del7...@gmail.com> wrote:
> > > Given a 2D board containing 'X' and 'O', capture all regions surrounded
> > by
> > > 'X'.
>
> > > A region is captured by flipping all 'O's into 'X's in that surrounded
> > > region .
>
> > > For example,
>
> > > X X X X
> > > X O O X
> > > X X O X
> > > X O X X
>
> > > After running your function, the board should be:
>
> > > X X X X
> > > X X X X
> > > X X X X
> > > X O X X
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To unsubscribe from this group and stop receiving emails from it, send an
> > email to algogeeks+unsubscr...@googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.


Reply via email to