hashmap - Is it possible to create copy of Map Iterators in Java? -
public boolean placelizardsbydfs(int noofqueens){ if(noofqueens == 0) { return true; } else { iterator itforrow = allowedrows.entryset().iterator(); while (itforrow.hasnext()) { double temprow = (double) ((map.entry) itforrow.next()).getkey(); iterator itforcolumn = allowedcolumns.entryset().iterator(); while(itforcolumn.hasnext()) { double tempcolumn = (double) ((map.entry) itforcolumn.next()).getkey(); placequeen(temprow, tempcolumn); if (placelizardsbydfs(noofqueens - 1)) return true; else removequeen(temprow, tempcolumn, temprangeforrow, temprangeforcolumn); } } return false; } }
i'm trying solve n queens problem. seems bigger inputs, code inefficient. i'm trying optimize reducing no. of rows , columns search deeper levels of recursion. possible pass copy of iterator map? problem i'm facing here whether can pass new iterator next level of recursion without iterator @ higher level getting affected since java call reference?
Comments
Post a Comment