求大神帮助,改个代码~~
import java.util.LinkedList;
public class Queen3 {
static LinkedListBorder queue = new LinkedListBorder();
public static void main(String args[]){
for(int i=0;iBorder.SIZE;i++){
Border b = new Border();
b.border[0][i] = true;
queue.addLast(b);
}
do{
Border tempB = queue.peek();
place(tempB);
}
while(!queue.isEmpty());
}
static void place(Border fb){
for(int i=0;iBorder.SIZE;i++){
if(!fb.isUnderAttack(fb.pRow+1,i)){
Border b = new Border(fb,fb.pRow+1);
b.border[b.pRow][i] = true;
if(b.pRow=Border.SIZE-1){
print(b);
}
else Queen3.queue.addLast(b);
}
}
Queen3.queue.pollFirst();
}
public static void print(Border b){
for(int i=0;iBorder.SIZE;i++){
for(int j=0;jBorder.SIZE;j++){
if(b.border[i][j])
System.out.print(1 );
else System.out.print(0 );
}
System.out.println();
}
System.out.println();
}
}
class Border{
static final int SIZE = 8;
boolean[][] border ;
int pRow; 准备放置皇后的行
Border(){
border = new boolean[SIZE][SIZE];
pRow = 0;
}
Border(Border b,int row){
border = new boolean[SIZE][SIZE];
pRow = row;
for(int i=0;ipRow;i++)
for(int j=0;jSIZE;j++)
border[i][j] = b.border[i][j];
}
boolean isUnderAttack(int row,int col){
int i,j;
j=row-1;
while(j=0){
if(border[j][col]) return true;
j–;
}
i=row-1;j=col-1;
while(i=0&&j=0){
if(border[i][j]) return true;
i–;
j–;
}
i=row-1;j=col+1;
while(i=0&&jSIZE){
if(border[i][j]) return true;
i–;
j++;
}
return false;
}
boolean placeFine(){
return (pRow=SIZE);
}
}