-
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
Abwas submitting percolation assignment #2
base: master
Are you sure you want to change the base?
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.
Good code, but how you name your variables, properly formating your code, or even using the proper javadoc style comment could improve it.
Please do address my comments...
{ | ||
checkBounds(a, b); | ||
int x = b; | ||
int y = a; |
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 don't need these variables. Why don't you just name method parameters a and b to x and y?
if (b > gridLength || b < 1) | ||
{ | ||
throw new IndexOutOfBoundsException("column index b out of bounds"); | ||
} |
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 code could be better formatted.
isOpen[virtualBottomIndex] = true; /// open virtual bottom site | ||
|
||
percolation = new WeightedQuickUnionUF(arraySize); | ||
fullness = new WeightedQuickUnionUF(arraySize); |
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.
fullness doesn't contain bottom virtual site, then could be represented with arraySiye -1 elements.
for (int b = 1; b <= n; b++) | ||
{ | ||
/// connect all top row sites to virtual top site | ||
int a = 1; |
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.
Don't need this variable.
int indexToLeft = siteIndex(a, b - 1); | ||
percolation.union(siteIndex, indexToLeft); | ||
fullness.union(siteIndex, indexToLeft); | ||
} |
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're repeating this pattern 4 times. You could instead create a "private void connect(int siteIndex, int row, int col)" method where you could first check row and column are valids and that the cell is open, before creating the connection...
public boolean isFull(int a, int b) | ||
{ | ||
int siteIndex = siteIndex(a, b); | ||
//return (percolation.connected(virtualTopIndex,siteIndex) && isOpen[siteIndex]); |
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 remove this comment, it's not needed at all...
} | ||
else { | ||
return isOpen[siteIndex(1,1)]; | ||
} |
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 could have used the ternary operator here instead of the if else...
private double[] thresholdResults; | ||
|
||
private int T; | ||
// perform T independent computational experiments on an n-by-n grid |
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 a well formatted javadoc comment and please could you place it closer to PercolationStats
// converts between two dimensional coordinate system and site array index. | ||
// throws exceptions on invalid bounds. valid indices are 1 : n^2 | ||
// a is the row; b is the column | ||
private int siteIndex(int a, int b) |
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.
naming your variables row and column instead of a and b will make your code much more readable. Please could you update this code to use row and column instead of a and b?
// holds each experiment's percolation threshold result | ||
private double[] thresholdResults; | ||
|
||
private int T; |
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.
non final static fields in java shouldn't be capitabilized. Please could you call this one trial instead?
public void open(int row, int col) // open site (row, col) if it is not open already | ||
public boolean isOpen(int row, int col) // is site (row, col) open? | ||
public boolean isFull(int row, int col) // is site (row, col) full? | ||
public int numberOfOpenSites() // number of open sites |
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 implement this one... Please could you implement it?
No description provided.