I have done a lot of researches but all of them were either recursion or not what I'm currently looking for. I'm trying to create an N-Queens program using LinkedStack instead of recursion, LinkedStack will take object NQueen, not just a bunch of integer. This is my first time experience doing this, even though I understand the algorithm but I just have no clue how to implement it. Like how can I compare a queen to the last queen in the stack, and how do they store each position that fit that 2 queens don't attack each other. I'm so lost, if possible some codes how to implement it would be great.
public class NQueen {
private static int numSolutions;
private int col;
private int row;
public int getCol()
{
return col;
}
public int getRow()
{
return row;
}
public void setCol(int num){
col= num;
}
public void setRow(int num) {
row= num;
}
public NQueen(int newRow, int newColumn) {
this.row = newRow;
this.col = newColumn;
}
public void solve(NQueen Queen, int n ) {
int current =0;
LinkedStack<Object> stack = new LinkedStack<>();
stack.push(Queen);
while(true) {
while(current < n) {
}
}
}
public boolean conflict(NQueen Queen) {
for(int i= 0; i < stack.size(); i++) {
}
//Check if same column or same diagonal
return true;
}
}
This is my return itemAt(int n) that I implement in LinkedStack. Thank you for your help.
/**
*
* @precondition
* 0 <= n and n < size( ).
* @postcondition
* The return value is the item that is n from the top (with the top at
* n = 0, the next at n = 1, and so on). The stack is not changed
*
**/
public Object itemAt(int n) {
int index = n;
if ((n<0) && (n >= size())) {
throw new EmptyStackException();
}
int i = 0;
while (i < n) {
this.pop();
i++;
}
this.peek();
return peek();
}