The path of C pointer programming and the path of pointer Programming
// Example of a pointer in a search algorithm
// Maze Algorithm
// The longest time used for search is deep-first search and breadth-first search.
// The deep priority search is like the name, and the search for each road is always the end,
// Stack data structure is specially set to prevent ideas
// You can exit from the starting point every time you find the idea.
//
//
// Search for breadth first
// The breadth-first-in-first-out feature of the queue is used to put each search result into the queue,
// Conditions such as troubleshooting
//
// Backtracking
// Enumerate every possible judgment. If it can be executed, it can return the start point if it cannot.
// The implementation of Queen eight: backtracking
# Include <iostream>
# Include <cstdio>
# Include <cmath>
Using namespace std;
Int a [9] = {100 };
// Used to store the number of solutions
Int count = 0;
Int Place (int I, int value)
{
Int j;
If (I = 1)
Return 1;
For (j = 1; j <I; ++ j)
{
If (a [j] = value)
Return 0;
If (abs (I-j) = abs (value-a [j])
Return 0;
}
Return 1;
}
Void ShowResult ()
{
Int I, j;
For (j = 1; j <= 8; ++ j)
{
For (I = 1; I <a [j]; ++ I)
{
Printf ("*");
}
Printf ("Q ");
For (I = I + 1; I <= 8; ++ I)
{
Printf ("*");
}
Printf ("\ n ");
}
}
Void Backtrack (int t)
{
Int I;
If (t> 8)
{
Printf ("*********************");
ShowResult ();
Count ++;
Return;
}
Else
{
For (I = 1; I <= 8; ++ I)
{
If (Place (t, I ))
{
A [t] = I;
Backtrack (t + 1 );
}
}
}
}
Void ShowCount ()
{
Printf ("\ n eight queens Total % d solutions: \ n", count );
}
Int main ()
{
Backtrack (1 );
ShowCount ();
Return 0;
}