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

Abwas submitting percolation assignment #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Abwas
Copy link

@Abwas Abwas commented Jun 20, 2017

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.

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;

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");
}

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);

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;

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);
}

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]);

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)];
}

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

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)

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;

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

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?

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