Created
February 22, 2013 19:56
-
-
Save charlespunk/5016116 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Implement the "paint fill" function that one might see on many image editing 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Color{ | |
Black, White, Red, Yellow, Creen | |
} | |
public static void paint(int[][] screen, int x, int y, Color originalColor, Color updatedColor){ | |
if(x < 0 || y < 0 || x >= screen[0].length || y >= screen.length) return; | |
if(screen[x][y] == originalColor){ | |
screen[x][y] = updatedColor; | |
paint(screen, x + 1, y, originalColor, updatedColor); | |
paint(screen, x - 1, y, originalColor, updatedColor); | |
paint(screen, x, y - 1, originalColor, updatedColor); | |
paint(screen, x, y + 1, originalColor, updatedColor); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment