Question: using java 1. Edit the file Percolation.java to complete the TODO items. 2. You will need to create a UnionFind object variable, initialize it and

using java

1. Edit the file Percolation.java to complete the TODO items.

2. You will need to create a UnionFind object variable, initialize it and update&access it to 'solve' the percolation problem.

3. Your UF object will be initialized in the Percolate constructor, updated in the openmethod, and accessed in the isFull and percolates method.

public class Percolation {

int N;

boolean[] open;

// TODO: more fields to add here

public Percolation(int N) {

this.N = N;

this.open = new boolean[N*N];

// TODO: more to do here

}

// open site (row i, column j) if it is not already

public void open(int i, int j) {

open[i*N+j] = true;

// TODO: more to do here.

}

// is site (row i, column j) open?

public boolean isOpen(int i, int j) {

return open[i*N+j];

}

// is site (row i, column j) full?

public boolean isFull(int i, int j) {

// TODO

return false;

}

// does the system percolate?

public boolean percolates() {

// TODO

return false;

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!