Examples of pointers in search algorithms
Maze algorithm
The longest search is in depth-first search and breadth-first search
Depth-First search is like a name, searching the end of every road,
In order to prevent the idea, specially set up the stack this data structure
So that every time you find the idea of the time can also exit to the starting point.
//
//
Breadth First Search
Breadth-first search is to use the nature of the first-out nature of the queue, put each search results into the queue,
Exclusion of ideas and other conditions
//
Backtracking method
is to enumerate each possible judgment, and if it can be executed, it is not possible to return to the beginning of the place
The realization of the eight Queens: Backtracking method
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace Std;
int a[9] = {100};
Number of solutions to store
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 queen's question total%d solutions: \ n", count);
}
int main ()
{
Backtrack (1);
Showcount ();
return 0;
}
C Pointer Programming Path---tenth notes