Results 1 to 2 of 2
  1. #1
    spinter is offline Member
    Join Date
    Oct 2011
    Posts
    18
    Rep Power
    0

    Default 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. #2
    spinter is offline Member
    Join Date
    Oct 2011
    Posts
    18
    Rep Power
    0

    Default 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 09:08 PM.

Similar Threads

  1. Replies: 2
    Last Post: 07-18-2011, 08:11 AM
  2. Convert C++ code to Java
    By napoleon in forum New To Java
    Replies: 2
    Last Post: 03-07-2010, 08:44 AM
  3. Convert java code to midlet code
    By coldvoice05 in forum New To Java
    Replies: 1
    Last Post: 08-12-2009, 12:14 PM
  4. Convert java code to midlet code
    By coldvoice05 in forum Advanced Java
    Replies: 1
    Last Post: 08-09-2009, 02:21 PM
  5. Pseudocode to java (HELP)
    By lordrowin in forum New To Java
    Replies: 1
    Last Post: 02-02-2008, 09:54 AM

Posting Permissions

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