Skip to content
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

Flood fill in java #1003

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

harper0201
Copy link

add java code for implementation of flood fill

@Amaras
Copy link
Member

Amaras commented Sep 6, 2022

Hi, thank you for your interest in the Algorithm Archive!
We will try to review your code as quickly as possible to get it merged in if we feel your code is high enough quality.

However, the first step of admissibility is not yet reached: you need to get your code to compile on a Docker Ubuntu-based environment, which, as I am writing this, just failed.
Below is the full error (slightly reformatted):

contents/flood_fill/code/java/main.java:5: error: cannot find symbol
        flood_fill f = new flood_fill();
        ^
  symbol:   class flood_fill
  location: class main

contents/flood_fill/code/java/main.java:5: error: cannot find symbol
        flood_fill f = new flood_fill();
                                   ^
  symbol:   class flood_fill
  location: class main

contents/flood_fill/code/java/main.java:6: error: cannot find symbol
        Point start = new Point(0,0);
        ^
  symbol:   class Point
  location: class main

contents/flood_fill/code/java/main.java:6: error: cannot find symbol
        Point start = new Point(0,0);
                                    ^
  symbol:   class Point
  location: class main

Please fix it, so we can review and eventually merge your code in.

@harper0201
Copy link
Author

Hi,
Thanks for your patience. I just committed a new version which is already tested in my ubuntu-based environment. Please help check it.

@Amaras
Copy link
Member

Amaras commented Sep 7, 2022

Thank you for the reactivity (relative to timezones, of course)!
If this compiles, I'll try to get someone to review it :)

@Amaras Amaras added Implementation This provides an implementation for an algorithm. (Code and maybe md files are edited.) lang: java Java programming language labels Sep 7, 2022
Copy link
Member

@Amaras Amaras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked your code before going to sleep, and it was empty.
Apparently your last commit truncated your flood_fill.java file, and outright deleted your Main.java file.
Please fix that, so we can review your code

@harper0201
Copy link
Author

Hi,
Thanks for your time and patience. Maybe because I did something wrong about git operations, so it became a empty file. I have already fixed it. Could you please check it again ?

@Amaras Amaras changed the title Chosen algorithm in java Flood fill in java Sep 8, 2022
Amaras
Amaras previously approved these changes Sep 8, 2022
Copy link
Member

@Amaras Amaras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, so while I'm not a Java specialist, the code was clear enough for me to approve it. I would ask for a second opinion, but I don't know anyone who is comfortable enough reviewing Java code :/
The only thing that annoys me is your package thing, but apart from that, I have nothing to say about the code.

contents/flood_fill/code/java/flood_fill.java Show resolved Hide resolved
Comment on lines 14 to 15
if (p.x < 0 || p.x >= row || p.y < 0 || p.y >= col) return false;
return true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe you can just do:

Suggested change
if (p.x < 0 || p.x >= row || p.y < 0 || p.y >= col) return false;
return true;
return (p.x < 0 || p.x >= row || p.y < 0 || p.y >= col);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, wrong call: it was missing a ! operator before the parenthesis...

Co-authored-by: Sammy Plat <sammy@sammyplat.fr>
@Amaras Amaras dismissed their stale review September 10, 2022 17:04

Error in the suggestions

Copy link
Member

@Amaras Amaras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, since you didn't respond to my last few comments, here is a new review.
Since you removed one line when removing the if statement in inbound(), you'll need to adjust the line numbers as well.
Looking forward to your next commit.

}
public static boolean inbound(int[][] grid, Point p){
int row = grid.length, col = grid[0].length;
return (p.x < 0 || p.x >= row || p.y < 0 || p.y >= col);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I mislead you earlier, this should be the correct way:

Suggested change
return (p.x < 0 || p.x >= row || p.y < 0 || p.y >= col);
return !(p.x < 0 || p.x >= row || p.y < 0 || p.y >= col);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Implementation This provides an implementation for an algorithm. (Code and maybe md files are edited.) lang: java Java programming language
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants