/ * * Created on 2003-3-28 * n Queen problem algorithm. * See the chessboard as a coordinate system, with the origin (0, 0) in the lower left corner. Each point of the coordinate system is a POINT class. * Each queen is a Queen object Queen. * Judging whether the coordinates of a point is in, a function of a royal control is queen.isunderControl (Point). * * / Package bia.arithmetic;
Import java.util.date;
/ ** * @Author administrator * * to change this generated comment Go to * window> preferences> java> code generation> code and comments * / public class elen {
Queen [] stack = new queen [8]; int sp = 0; int NUM = 0;
Public EightQueen () {num = 8; stack = new queen [num]; sp = 0;
Public EightQueen (int Num) {this.Num = Num; stack = new queen [num]; sp = 0;
/ ** * Print the queen 's coordinates list. * @Renzc * * / public void list () {system.out.println ("Begin List The Stack Point:"); for (int i = 0; i / ** * Main algorithm process. * @Administrator * * / public void Calc () {sp = 0; Stack [SP ] = new queen (); while (sp> = 0 && sp <= number - 1) {queen = getQueen (sp); if (null == queen) {boolean flag = true; while (flag) {--SP; if (sp <0) Break; if (stack [sp] .pos.y == Num - 1) { Else {Stack [SP ]. POS.Y ; Flag = false; for (int K = 0; K } Else {stack [sp ] = queen;}}}} Public Queen getQueen (int x) {boolean flag = true; int y = 0; while (flag) {flag = false; for (int i = 0; i Class Point {Int x, y; Public void println () {system.out.println ("The point is [x, y] = [" x "," y "]");} PUBLIC POINT () {x = 0; y = 0;} Public Point (int x, int y) {this.x = x; this.y = y;} / ** * @return int * / public int GETX () {Return x;} / ** * @Return Int * / public int game () {return y;} / ** * sets the x. * @Param x the x to set * / public void setx (int x) {this.x = x;} / ** * sets the y. * @Param y the y to set * / public void setY (int y) {this.y = y;}}