Question
Eight cross C++ program: Fix program please, I believe the issue is in the ok function. I left some lines of sudo code that I
Eight cross C++ program: Fix program please, I believe the issue is in the ok function. I left some lines of sudo code that I couldn't figure out.
In the solution to this problem, use the backtracking scheme that we covered in class. Write a program which allocates the integers 1-8 to the squares in the figure above, subject to the restrictions that no two adjacent squares contain consecutive integers. By adjacent we mean vertically, horizontally, or diagonally.
#include int main(){ int q[8]; q[0]=0; /*board setup section*/ int c=0; bool from_backtrack=false; while(true){ while(c<8){ if(!from_backtrack) { /*column section*/ c++; /*increase column number */ if(c==8) break; /*check column number, break if c == 8*/ q[c]=1; /*initialize row number */ } from_backtrack=false; while(q[c]<8){ /*row section*/ q[c]++; /*increase row number */ if(q[c]==8) { backtrack(c); /*check row number, call backtrack*/ from_backtrack = true; } if(ok(q,c)) break; /*call ok function, break if true */ } } print(q) ; /*print section*/ backtrack(c); /*backtrack section*/ from_backtrack=true; } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started