Heya, I was hoping someone here can help. I have a CS project due for 2PM today (yes yes I know). I was actually finished but now I see they slightly changed the brief so here I am...
Anyways, I have a class called Percolation that takes an int and a boolean (boolean decides weather it uses Quick find or weighted quick find algorithm). The problem is that I need to declare my quick find structure before I know if the boolean is true or false, and I have no idea how to do that.
Here's what I have at the moment (without the boolean):
And this is the type of thing I need:
Just casting it doesn't work because it doesn't have any of the properties it needs.
Any suggestions would be great,
Thanks
Anyways, I have a class called Percolation that takes an int and a boolean (boolean decides weather it uses Quick find or weighted quick find algorithm). The problem is that I need to declare my quick find structure before I know if the boolean is true or false, and I have no idea how to do that.
Here's what I have at the moment (without the boolean):
Code:
public class Percolation
{
private QuickFindUF uf;
private int SIZE;
private boolean[][] grid;
public Percolation(int N)
{
grid = new boolean [N][N];
uf = new QuickFindUF((N*N) + 2);
SIZE = N;
}
And this is the type of thing I need:
Code:
public class Percolation
{
private boolean[][] grid;
private int SIZE;
private Object uf;
public Percolation(int N, boolean weighted)
{
grid = new boolean[N][N];
if(weighted)
uf = new WeightedQuickUnionUF((N*N)+2);
else
uf = new QuickFindUF((N*N)+2);
SIZE = N;
}
Just casting it doesn't work because it doesn't have any of the properties it needs.
Any suggestions would be great,
Thanks