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

PERCOLATION #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

KunleMichaels
Copy link

No description provided.

Copy link

@erictoguem erictoguem left a comment

Choose a reason for hiding this comment

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

Please could you implement what is asked in the problem description while respecting the stated constraints?

for (int j = 0; j < N; j++) {
grid[i][j] = false;
}
}

Choose a reason for hiding this comment

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

This is not needed, the default value of boolean primitive is false.

public Percolation(int n) // create n-by-n grid, with all sites blocked
public void open(int row, int col) // open site (row, col) if it is not open already
public boolean[][] grid;
private int nos = N;

Choose a reason for hiding this comment

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

I couldn't find where you declared N...

return num;
}
public void open(int row, int col) { // open site (row, col) if it is not open already
grid[i - 1][j - 1] = true; // (i - 1, j - 1) is the site I just opened

Choose a reason for hiding this comment

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

What is i and j? Where does it come from? sorry I can't see how it gets passed to this method...

private StdRandom randomGenerator;

public Percolation(int n) { // create n-by-n grid, with all sites blocked
nos = N;

Choose a reason for hiding this comment

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

You didn't check n is valid number...

return num;
}
public void open(int row, int col) { // open site (row, col) if it is not open already
grid[i - 1][j - 1] = true; // (i - 1, j - 1) is the site I just opened

Choose a reason for hiding this comment

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

You didn't check row and column were valids.

public void open(int row, int col) { // open site (row, col) if it is not open already
grid[i - 1][j - 1] = true; // (i - 1, j - 1) is the site I just opened
if (i - 2 >= 0 && isOpen(i - 1, j)) { // left
connect.union((j - 1) * nos + i - 1, (j - 1) * nos + i - 2);

Choose a reason for hiding this comment

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

Please could you use toNum method you created, instead of recomputing it... Same 3 times bellow...

public int numberOfOpenSites() // number of open sites
public boolean percolates() // does the system percolate?
{
return grid[i - 1][j - 1] == false;

Choose a reason for hiding this comment

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

This is not checking the site is full, in order for it to be full there should be an open path from the site to a top row site.


public static void main(String[] args) // test client (optional)
public int numberOfOpenSites(){ // number of open sites
return al.length();

Choose a reason for hiding this comment

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

This will always return 0 as this list has never been changed...

if (connect.connected(i, i2)) return true;
}
}
return false;

Choose a reason for hiding this comment

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

In order for the system to percolate, there should be a full site in the bottom row. And you're not checking it...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants