Question
Given: char image[][] = { {'*','*',' ',' ',' ',' ',' ',' ','*',' '}, {' ','*',' ',' ',' ',' ',' ',' ','*',' '}, {' ',' ','
Given:
char image[][] = { {'*','*',' ',' ',' ',' ',' ',' ','*',' '}, {' ','*',' ',' ',' ',' ',' ',' ','*',' '}, {' ',' ',' ',' ',' ',' ','*','*',' ',' '}, {' ','*',' ',' ','*','*','*',' ',' ',' '}, {' ','*','*',' ','*',' ','*',' ','*',' '}, {' ','*','*',' ','*','*','*','*','*','*'}, {' ',' ',' ',' ',' ',' ',' ',' ','*',' '}, {' ',' ',' ',' ',' ',' ',' ',' ','*',' '}, {' ',' ',' ','*','*','*',' ',' ','*',' '}, {' ',' ',' ',' ',' ','*',' ',' ','*',' '} };
Determine the number of organisms in an image (2d array), and label each organism.
Signature: public static int howManyOrganisms(char[][] image)
Description: Given a 2d array of characters, where an asterisk (*) marks a non-empty cell. An organism is defined as all cells connected directly to other cells in the up/down/left/right (not diagonal) directions.
The method signature above is not a recursive method. Instead, it iterates through the image and as soon as it encounters a new organism, it calls a recursive method (that you define) that labels the newly found organism.
Here is what I have so far:
public static int howManyOrganisms(char[][] image){ for(int row = 0; row < image.length; row++){ for(int col = 0; col < image[row].length; col++){ } } }
Then I know I need to have an if the character is an * I need to call the other recursive method, but I am having a hard time understanding what goes in the recursive method.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started