java:implement 8 queen using depth first search

后端 未结 3 1834
你的背包
你的背包 2020-12-12 06:09

i am try to implement 8 queen using depth search for any initial state it work fine for empty board(no queen on the board) ,but i need it to work for initial state if there

3条回答
  •  心在旅途
    2020-12-12 07:03

    You asked for ideas on how to solve it (as distinct from solutions!) so, here's a couple of hints:

    Hint #1:

    If you get a StackOverflowError in a recursive program it can mean one of two things:

    • your problem is too "deep", OR
    • you've got a bug in your code that is causing it to recurse infinitely.

    In this case, the depth of the problem is small (8), so this must be a recursion bug.

    Hint #2:

    If you examine the stack trace, you will see the method names and line numbers for each of the calls in the stack. This ... and some thought ... should help you figure out the pattern of recursion in your code (as implemented!).

    Hint #3:

    Use a debugger Luke ...

    Hint #4:

    If you want other people to read your code, pay more attention to style. Your indentation is messed up in the most important method, and you have committed the (IMO) unforgivable sin of ignoring the Java style rules for identifiers. A method name MUST start with a lowercase letter, and a class name MUST start with an uppercase letter.

    (I stopped reading your code very quickly ... on principle.)

提交回复
热议问题