The path of C pointer programming and the path of pointer Programming

Source: Internet
Author: User

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;


}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.