mirror of
https://github.com/RustyRaptor/CS-272.git
synced 2026-12-03 15:55:22 -07:00
Started Lab 8
This commit is contained in:
1 parent
52d3a5908e
commit
e23b55517e
2 files changed
+45
-43
No files matched your search
+43
-43
@@ -1,43 +1,43 @@
|
||||
public class NQueen {
|
||||
public static void main(String[] args) {
|
||||
|
||||
}
|
||||
public static ArraylistStack<Integer> solveNQueen(int N) {
|
||||
ArraylistStack<Integer> board = new ArraylistStack<Integer>();
|
||||
Integer rowid = 1;
|
||||
Integer Qpos = 1;
|
||||
|
||||
while (board.size() < N){
|
||||
while (Qpos <= N) {
|
||||
boolean conflict = checkConflict(Qpos);
|
||||
if (conflict) {
|
||||
board.push(Qpos);
|
||||
Qpos = 1;
|
||||
rowid = board.size() + 1;
|
||||
} else {
|
||||
Qpos++;
|
||||
}
|
||||
}
|
||||
while (!board.isEmpty() && Qpos >= N) {
|
||||
if (board.pop() < N) {
|
||||
board.push(++Qpos);
|
||||
}else {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean checkConflict(Integer Qpos,
|
||||
ArraylistStack<Integer> board){
|
||||
int dist = 1;
|
||||
while (!board.pop().equals(Qpos) && Math.abs(Qpos - board.pop()) != dist){
|
||||
dist++;
|
||||
}
|
||||
return board.size() == 0;
|
||||
}
|
||||
|
||||
public static void printBoard(ArraylistStack<Integer> board){
|
||||
|
||||
}
|
||||
}
|
||||
//public class NQueen {
|
||||
// public static void main(String[] args) {
|
||||
//
|
||||
// }
|
||||
// public static ArraylistStack<Integer> solveNQueen(int N) {
|
||||
// ArraylistStack<Integer> board = new ArraylistStack<Integer>();
|
||||
// Integer rowid = 1;
|
||||
// Integer Qpos = 1;
|
||||
//
|
||||
// while (board.size() < N){
|
||||
// while (Qpos <= N) {
|
||||
// boolean conflict = checkConflict(Qpos);
|
||||
// if (conflict) {
|
||||
// board.push(Qpos);
|
||||
// Qpos = 1;
|
||||
// rowid = board.size() + 1;
|
||||
// } else {
|
||||
// Qpos++;
|
||||
// }
|
||||
// }
|
||||
// while (!board.isEmpty() && Qpos >= N) {
|
||||
// if (board.pop() < N) {
|
||||
// board.push(++Qpos);
|
||||
// }else {
|
||||
//
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public static boolean checkConflict(Integer Qpos,
|
||||
// ArraylistStack<Integer> board){
|
||||
// int dist = 1;
|
||||
// while (!board.pop().equals(Qpos) && Math.abs(Qpos - board.pop()) != dist){
|
||||
// dist++;
|
||||
// }
|
||||
// return board.size() == 0;
|
||||
// }
|
||||
//
|
||||
// public static void printBoard(ArraylistStack<Integer> board){
|
||||
//
|
||||
// }
|
||||
//}
|
||||
@@ -0,0 +1,2 @@
|
||||
public interface QueueInterface <E> {
|
||||
}
|
||||
Reference in new issue
Block a user