Reputation: 129
So I have been trying to implement the Flood Fill Algorithm using 2D Array. I have had success in filling the Array but I am wondering if there is any way to calculate the number of areas that are left unpainted. Just need an idea on how to do this, not asking for any code snippet.
Input :
Output :
Upvotes: 2
Views: 1000
Reputation: 8244
i = 0
Pick random unfilled dot, increase i by 1
Flood-fill from there, but in a different color
Repeat until no dots left
i is the amount of groups.
You might want to first create some set of unfilled dots and remove dots in step 1 and 2 to avoid linear scanning through the 2d-array to look for new unfilled dots.
Upvotes: 2
Reputation: 6246
Algorithm:-
Start from unfilled point and do floodfill from that point.
Count all points filled till floodfill ends
the count is u r area for enclosed figure.
Upvotes: 0