I recently looked at the data structure of the book, now the textbook or use the written algorithm of C/s + +, compiled or in console mode, if you can use these data structure algorithms in the SDK, then you can develop the algorithm of Windows programs to improve learning, not in The monotonous console mode looks at the cold characters to learn the data structure, so that learning can learn to invoke Windows API and Windows programming, on the other hand can learn data structure. I hope my learning method is helpful to the novice Windows friends.
This is the Maze program developed using the SDK (F1 key begins).
Maze algorithm or the old way, backtracking and stack implementation, I am using the stack implementation. Use a two-way linked list to touch the stack, using a ptrfirst and a ptrlast and a stack-bottom and stack-top pointer to define a stack-element structure that holds the position in the maze.
typedef struct _tagNode {
int nRow;
int nColumn;
struct _tagNode* next;
struct _tagNode* previou;
} Node;
Defines a tag array
BOOL bPass[ Row ][ Column ]; // Row 和 Column 为迷宫大小.
The method of realizing the main pseudocode of Maze algorithm.
A. Start from the beginning, judge all directions of the ball is feasible, if one direction is feasible, then move in that direction.
Forward position into the stack.
Condition: The forward direction is a wall, then the direction cannot forward.
Forward and direction if it is passed, the direction cannot be forward.
if (Canmove (Gnrow, Gncolumn, right)
{
Gncolumn + = MoveRight;/forward
bpass[Gnrow] [ Gncolumn] = TRUE; Mark through the Position
//Gnrow, gncolumn position into the stack.
Else if (Canmove (Gnrow, Gncolumn, left))//The right side does not pass, to the right.
{
Gncolumn + = moveLeft/forward
bpass[Gnrow] [gncolumn] = TRUE;//Mark through location
//Gnrow, G Ncolumn position into the stack.
}
Else if (Canmove (Gnrow, Gncolumn, Forward))//left side does not pass, forward.
{
Gncolumn + = Moveforward/forward
bpass[Gnrow] [gncolumn] = TRUE;//Mark through location
//Gnrow, Gncolu MN position into stack.
}
Else if (Canmove (Gnrow, Gncolumn, back))//forward not pass, backward.
{
Gncolumn + = Moveback/forward
bpass[Gnrow] [gncolumn] = TRUE;//Mark through location
//Gnrow, Gncolumn Position into the stack.
}
B. All directions are not feasible, return to the previous position, using the back stack operation, back to a.
else if ( CanMove( gnRow, gnColumn, back ) )
{}
A, B keep repeating until you find the exit, or traverse the maze (stack empty)
if 为迷宫出口
bSearch = FALSE;
if 栈为空 // 没有出口,
bSearch = FALSE;