-
Notifications
You must be signed in to change notification settings - Fork 12
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
base: master
Are you sure you want to change the base?
PERCOLATION #5
Conversation
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.
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; | ||
} | ||
} |
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 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; |
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.
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 |
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.
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; |
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.
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 |
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.
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); |
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.
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; |
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 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(); |
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 will always return 0 as this list has never been changed...
if (connect.connected(i, i2)) return true; | ||
} | ||
} | ||
return false; |
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.
In order for the system to percolate, there should be a full site in the bottom row. And you're not checking it...
No description provided.