programs. That is, given a screen (represented by a two-dimensional array of colors),
a point, and a new color, fill in the surrounding area until the color changes from the
original color.
soln
enum Color{ red, yellow, blue, green, white ;}
boolean helper (Color [][] screen, int x, int y, Color ncolor, Color ocolor) {
if ( x<0 || x>= screen[0].length() || y<0 || y>=screen.length())
return false;
if (screen[y][x] == ocolor) {
screen[y][x] = ncolor;
helper (screen, x+1,y, ncolor, ocolor);
helper (screen, x-1,y, ncolor, ocolor);
helper (screen, x,y+1, ncolor, ocolor);
helper (screen, x,y-1, ncolor, ocolor);
} return true;
}
boolean paintfill (Color [][] screen, int x, int y, Color ncolor ) {
if (screen[y][x] == ncolor) return false;
return helper(screen, x, y, ncolor, screen[y][x]);
}