Started Lab 8

This commit is contained in:
RustyRaptor committed 2019-10-21 16:29:22 -06:00
1 parent 52d3a5908e
commit e23b55517e
2 files changed
+45 -43

No files matched your search

+43 -43
View File
@@ -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){
//
// }
//}
+2
View File
@@ -0,0 +1,2 @@
public interface QueueInterface <E> {
}