-
Notifications
You must be signed in to change notification settings - Fork 0
Assignment 4 - Code review request #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
karineek
wants to merge
28
commits into
assignment4_base
Choose a base branch
from
master
base: assignment4_base
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
49193e2
fix second comments of the code review
f61d053
final version of 4
feeac00
fix for 3
2afa747
fix for 4
1ed2e91
assignment 5, second commit
ce33dca
remove env. files
karineek a40d4e2
remove env. files
karineek 101c856
remove env. files
karineek 7d5e18a
remove env. files
karineek 32c04d4
remove env. files
karineek 637ef21
remove env. files
karineek 3875d6f
assignment 5, fix after code review
8b9c545
Merge origin/master
a35bdb9
assignment 5, fix build
95b497a
assignment 5, fix build - second try
dd83412
assignment 5, fix build - second try
9966ad7
brute force fix of commits
karineek e029e22
brute force fix of commits
karineek 9f039b5
brute force fix of commits
karineek c1d102c
brute force fix of commits
karineek 435aae2
assignment 5, fix error from code review
5094dfe
assignment 5, revert back to 1ed2e9114b64038435e525c76da636f13751803d
e927bb8
rename dict to alphabet
fd92daa
fix for recent code review
3921b2e
first commit, 6
defbadf
Basic working project for summit
edade50
code review's fix
a077a09
code review's fix
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
84 changes: 84 additions & 0 deletions
84
CodeU_Assignement_4/src/codeu_assignement_4/KEMIslandsFinder.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| package codeu_assignement_4; | ||
|
|
||
| /** | ||
| * | ||
| * @author Karine | ||
| * | ||
| * The class is an Algorithm that starts from the only public method countIslands which | ||
| * gets: a map and the size of the map (rxc) and returns the number of Islands in the map | ||
| */ | ||
| public class KEMIslandsFinder { | ||
|
|
||
| private boolean[][] visistedMap; | ||
|
|
||
| public int countIslands(int row, int col, boolean[][] map) | ||
| { | ||
| if ((row > 0) && (col > 0)) | ||
| { | ||
| if ((map.length == row) && (map[0].length == col)) | ||
| { | ||
| visistedMap = new boolean[row][col]; | ||
| return countIslands(map, 0, 0); | ||
| } | ||
| else | ||
| { | ||
| throw new IllegalArgumentException(); | ||
| } | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| /* Private Helpers */ | ||
| private int countIslands(boolean[][] map, int curr_row, int curr_col) | ||
| { | ||
| int currentNumberOfIslands = 0; | ||
|
|
||
| currentNumberOfIslands += countNewIsland(map,curr_row,curr_col); | ||
| markIslandAsVisited(map,curr_row,curr_col); | ||
|
|
||
| /* Move to the next location */ | ||
| if ((curr_col+1) < map[curr_row].length) | ||
| { | ||
| currentNumberOfIslands += countIslands(map, curr_row, curr_col + 1); | ||
| } | ||
| else if ((curr_row+1) < map.length) | ||
| { | ||
| currentNumberOfIslands += countIslands(map, curr_row + 1, 0); | ||
| } | ||
| else | ||
| { | ||
| /* Recursion End */ | ||
| } | ||
|
|
||
| return currentNumberOfIslands; | ||
| } | ||
|
|
||
| private void markIslandAsVisited(boolean[][] map, int curr_row, int curr_col) | ||
| { | ||
| /* Stop marking as one Island, if out of bound, marked or not an island */ | ||
| if ((map.length <= curr_row) || (curr_row < 0) || (curr_col < 0)) | ||
| { | ||
| return; | ||
| } | ||
| if ((map[curr_row].length <= curr_col) | ||
| || (!map[curr_row][curr_col]) | ||
| || (visistedMap[curr_row][curr_col])) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| visistedMap[curr_row][curr_col] = true; | ||
| for (int i = -1; i < 2; i++) | ||
| { | ||
| markIslandAsVisited(map,curr_row+i,curr_col); | ||
| markIslandAsVisited(map,curr_row,curr_col+i); | ||
| } | ||
| } | ||
|
|
||
| private int countNewIsland(boolean[][] map, int curr_row, int curr_col) | ||
| { | ||
| return ((map[curr_row][curr_col]) && | ||
| (!visistedMap[curr_row][curr_col])) ? 1 : 0; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method could be written a lot more simply as a pair of nested for loops iterating over the rows and columns.