windows - C++- 8 Queens program- chess edition -


i assigned utilize permutation code, , convert 8 queens program on chess board.

i think i've finished output keeps giving stack overflow , cannot find is, it's crazy!

here code below

#include <iostream> #include <iomanip> using namespace std; char board[8][8]; void clearboard(); void attempt(int n, int level, int possibility); void placequeen(int level, int possibility); void removequeen(int level, int possibility); bool currentpathsuccess(int n, int level, int possibility); bool currentpathstillviable(int level, int possibility); void processsuccessfulpath(int n);   int main() { int n;  clearboard(); cout << "permutation of integers 1 ? "; cin >> n; (int = 1; <= n; i++){     (int j = 1; j <= n; j++)     {         attempt(n, i, j);     } }  system("pause"); return 0; }  void clearboard() { (int = 0; < 8; i++) (int j = 0; j < 8; j++)     board[i][j] = '_'; }  void attempt(int n, int level, int possibility) { placequeen(level, possibility); if (currentpathsuccess(n, level, possibility)) {      processsuccessfulpath(n);  } else if (currentpathstillviable(level, possibility)) (int = 0; <= n; i++)     attempt(n, level + 1, possibility + 1); removequeen(level, possibility); }  void placequeen(int level, int possibility) { board[level][possibility] = 'q'; }  void removequeen(int level, int possibility) { board[level][possibility] = '_'; } bool currentpathsuccess(int n, int level, int possibility) { bool success = true; int = 0; int j = 0;    if (n > level)     success = false; else {      while ((i <= level - 1) && success)     {         success = board[i][j] != board[level][possibility];         i++;     } } return success; }  bool currentpathstillviable(int level, int possibility) { bool viable = true; int = 0; int j = 0; while ((i <= level - 1) && viable) {     viable = board[i][j] /*!= board[level][possibility]*/;     i++; } return viable; }  void processsuccessfulpath(int n) { (int = 0; <= n; i++) {     (int j = 0; j <= n; j++)     {         cout << setw(3) << board[i][j];     }     cout << endl; } cout << endl; } 

your attempt() recursive function call causing stack overflow. there problem. check out break condition inside function.


Comments

Popular posts from this blog

php - Magento - Deleted Base url key -

javascript - Tooltipster plugin not firing jquery function when button or any click even occur -

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -