Results 1 to 2 of 2
- 11-21-2011, 05:12 PM #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)
- 11-21-2011, 07:46 PM #2
Member
- Join Date
- Oct 2011
- Posts
- 18
- Rep Power
- 0
Re: how to convert this pseudocode to java code i dont know
i have that but sure its not wellJava 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); } } } } }Last edited by spinter; 11-21-2011 at 08:08 PM.
Similar Threads
-
Looking for pseudocode to convert Prefix Expression & Infix Expression to expression
By dragstang86 in forum New To JavaReplies: 2Last Post: 07-18-2011, 07:11 AM -
Convert C++ code to Java
By napoleon in forum New To JavaReplies: 2Last Post: 03-07-2010, 07:44 AM -
Convert java code to midlet code
By coldvoice05 in forum New To JavaReplies: 1Last Post: 08-12-2009, 11:14 AM -
Convert java code to midlet code
By coldvoice05 in forum Advanced JavaReplies: 1Last Post: 08-09-2009, 01:21 PM -
Pseudocode to java (HELP)
By lordrowin in forum New To JavaReplies: 1Last Post: 02-02-2008, 08:54 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks