Thread: how to convert this pseudocode to java code i dont know

1. Member
Join Date
Oct 2011
Posts
18
Rep Power
0

how to convert this pseudocode to java code i dont know

function Conflict (board, k): boolean
{Post: Returns true if a column or diagonal conflict between the queen standing in the k-th row and the previous ones. The position on the queens within each row vector is on the board}
i: = 1; conflict: = false
while (i <k) and (no conflict) to
if board [i] = board [k] o | board [i] - board [k] | = | i - k | then
conflict: = true
else i: = i + ​​1

Queens procedure (var solutions)
{Post: solutions containing all the solutions to the n queens problem solving var} [1 .. n], i: 1 .. n;

ReinasVueltaAtras procedure (solution, row, var solutions)
var i: 1 .. n
for i: = 1 to n do
solution [row]: = i
if not Conflict (solution, row) then
if row = n then solutions : = solutions U solution
else ReinasVueltaAtras (solution, row + 1, solutions)
Solution: = ∅
for i: = 1 to n do solution [i]: = 0
ReinasVueltaAtras (solution, 1, solutions)

2. Member
Join Date
Oct 2011
Posts
18
Rep Power
0

Re: how to convert this pseudocode to java code i dont know

Java Code:
```package reina;

/**
*

*/
public class Reina {

/**
* @param args the command line arguments
*/
public static boolean conflicto(int[] q, int k) {
int i = 0;
if ( q[i] == 1){
return false;}
if ( q[i] == q[k] || (q[i]-q[k]) == (i-k)){
return true;
}
else{
i++;
}
return false;
}

public static void Reinas(int soluciones){

}

public static void ReinasVueltaAtras(int [] solucion, int fila, int soluciones){
int n = 8;
for (int i = 1; i <= n; i++){
solucion[fila]= i;
if(!conflicto(solucion,fila)){
if(fila == i){
// soluciones = (int) soluciones + soluciones;
}else{
ReinasVueltaAtras(solucion,fila,soluciones);
}
for(  i = 1; i <= n ; i++){
solucion[i]= 0;
ReinasVueltaAtras(solucion,1,soluciones);
}
}
}
}
}```
i have that but sure its not well
Last edited by spinter; 11-21-2011 at 08:08 PM.

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•