Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7700397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:41:56+00:00 2026-05-31T22:41:56+00:00

Working on the N-queens problem. Having some difficult filling up the stack correctly. Was

  • 0

Working on the N-queens problem. Having some difficult filling up the stack correctly. Was hoping anyone could give me any pointers.

Right now my output is strange..There are only 7 nodes, but my ‘success’ boolean needs 8 for it to be true. And the head node is 2,1 when I thought it should be 1,2 since I’d be increasing the column.

I know I need to check for the diagonal also, but I’m taking it step by step.

The first thing I need to work out if my conflictCheck method. It never return true (for, yes there is a conflict). I’ll update shortly if I figure something out.

Hurray
8, 1
7, 1
6, 1
5, 1
4, 1
3, 1
2, 1

EDIT:

I’ve made some changes to the code for a more recursive attempt.
My new output is this:

The stack
1, 1

End of stack
Pushing next node
The stack
2, 1
1, 1

End of stack
Moving over one column
The stack
2, 2
1, 1

End of stack
problem
Moving over one column
The stack
2, 3
1, 1

End of stack

This is part of the code/work in progress. Right now, it’s running into an eternal loop, most likely from that while (conflictCheck)

    public static boolean conflictCheck() {
    QueenNode temp = head;
    //walk through stack and check for conflicts

    while(temp!=null) {
        //if there is no next node, there is no conflict with it
        if (temp.getNext() == null){
            System.out.println("No next node");
            if (queens.size() < 8 ) {
                return false;
            }
        }
        else if (temp.getRow() ==temp.getNext().getRow() || temp.getColumn() == temp.getNext().getColumn() ||
                diagonal(temp, temp.getNext())){
            return true;
        }
    }
    return false;
}

public static void mover(QueenNode n) {
    System.out.println("Moving over one column");

        n.setColumn(n.getColumn()+1);

    queens.viewPieces();
}

public static void playChess(int k, int total) {
    QueenNode temp= head;
    while (temp != null) {
        System.out.println("Pushing next node");

        queens.push(k,1);
        queens.viewPieces();
        //success
        if(k == 8){
            System.out.println("Hurray");
            success = true;
            return;
        }
        //conflict between pieces, loops through entire board
        while (conflictCheck()) {
            if (head.getColumn() != 8) {
                mover(head);
            }
            else {
                queens.pop();
                mover(head);
            }
        }

        playChess(k+1, total);                  
    }
}

public static void main(String[] args) {
    queens.push(1, 1);
    queens.viewPieces();
    success = false;
    playChess(2, total);
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T22:41:57+00:00Added an answer on May 31, 2026 at 10:41 pm

    temp != null && temp.getNext()!= null – for 8th queen the value temp.getNext() is null and it is not printed. Change to:

    while (temp != null ) {
                    System.out.println(temp.getRow() + ", " + temp.getColumn());
                    temp = temp.getNext();
                }
    

    Edit

    Change || to &&:

    if (temp.getRow() != temp.getNext().getRow() &&
                    temp.getColumn() != temp.getNext().getColumn()) {
                return false;
            }
    

    In code queens.push(queens.size()+1, 1); you always assign 1 as second argument. You should check all possibilities.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been working on the 8 queens problem but I got stuck. I don't
I'm working on a program to solve the n queens problem ( the problem
Working with dates in ruby and rails on windows, I'm having problems with pre-epoch
Working with python interactively, it's sometimes necessary to display a result which is some
Working on some code and I'm given the error when running it from the
Working with some basic java apps on CentOS 5 linux and I have my
Working with MVC 2 ad with the help of some friends I thought all
Working on this EF tutorial , I've difficult to understand the meaning of the
Working live URL showing problem: http://69.24.73.172/demos/newDemo/test.html The HTML : <div class="small-vote"> <a href="#" class="s
Working with C and Win32, I have a problem where my program freezes instead

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.