Question
I want to create some function in java (phseudo code will also help) that does the following. I have a 2d array of Objects called
I want to create some function in java (phseudo code will also help) that does the following.
I have a 2d array of Objects called vertices. Each vertice has a value of 0,1 or 2
the number of arrays of vertecies are (arrays containing 3 vertices) are determined by n = Math.pow(3,n-2) where n ranges from 1 to 10;
some n value is passed as a parameter and then i want to create a labeling function or class to do the following.
the label lentgh is equal to n-1
so if n =4 then the label should be 3 letters long.
Also the specified vertex in the array is given as a parameter so you know the place in the array where the specified vertex lies.
for example:
this is my constructor:
public PrecedenceGraph(int N)
{
/*
The constructor creates the precedence graph TN,
where N is passed as a parameter.\
*/
n = N;
tokens = new Queue(N);
maxnumberoftokens = N;
int numbox = 0;
if(n>1){
labellentgh = n-2;
}
if (N == 1){
Vertex v0 = new Vertex(0);
vertexarray = new Vertex[1][1];
vertexarray[0][0] = v0;
}
else if (N == 2){
numbox = (int) Math.pow(3,N-2);
vertexarray = new Vertex[3][numbox];
Vertex v0,v1,v2;
v0 = new Vertex(0);
v1 = new Vertex(1);
v2 = new Vertex(2);
vertexarray[0][0] = v0;
vertexarray[1][0] = v1;
vertexarray[2][0] = v2;
}
else if(N>2){
numbox = (int) Math.pow(3,N-2);
vertexarray = new Vertex[3][numbox];
for (int i = 0 ; i < numbox;i++){
for (int j = 0 ; j < 3; j++){
vertexarray[j][i] = new Vertex(j);
}
}
}
}
for example.
if n = 3 an array is created
[[0,1,2]]
if n = 4
[[0,1,2],[0,1,2]...... up until there is 9 arrays of [0,1,2]]
so if i want to genereate a label for n = 4 and the element surrounded in the brackets is :
[[0,1,2],[0,(1),2], [0,1,2]]
the label must be 11
also
n = 4
[[0,1,2],[0,1,2].,[0,1,2],[0,(1),2]..... up until there is 9 arrays of [0,1,2]]
101
every 3 arrays counts as a 0 1 or 2 for the first part.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started