// Base. h
# Include <stdio. h>
# Include <stdlib. h>
# Include <string. h>
# Define true 1
# Define false 0
# Define OK 1
# Define error 0
# Define overflow-2
Typedef int status;
// Stack. h
# Include "base. cpp"
# Define init_size 100 // initial storage space allocation
# Define increment 10 // increment of storage space allocation
Typedef struct {// position of column C in the r column in the maze
Int R;
Int C;
} Posttype;
Typedef struct {
Int ord; // the serial number of the current position in the path
Posttype seat; // current Coordinate
Int di; // the direction of the next Coordinate
} Selemtype; // stack element type
Typedef struct {
Selemtype * base; // stack base address, empty after being destroyed before construction
Selemtype * Top; // stack top
Int stacksize; // stack capacity
} Stack; // stack type
Status initstack (stack & S) {// construct an empty stack s
S. base = (selemtype *) malloc (init_size * sizeof (selemtype ));
If (! S. Base)
Exit (overflow); // storage allocation failed
S. Top = S. base;
S. stacksize = init_size;
Return OK;
} // Initstack
Status stackempty (stack s) {// If S is null, true is returned; otherwise, false is returned.
If (S. Top = S. Base)
Return true;
Return false;
} // Stackempty
Status push (stack & S, selemtype e) {// insert element e as the new top element of the stack.
If (S. top-S.base> = S. stacksize) {// stack full, append Space
S. base = (selemtype *) realloc (S. Base, (S. stacksize + increment) * sizeof (selemtype ));
If (! S. Base)
Exit (overflow); // storage allocation failed
S. Top = S. Base + S. stacksize;
S. stacksize + = increment;
}
* S. Top ++ = E;
Return OK;
} // Push
Status POP (stack & S, selemtype & E) {// If the stack is not empty, use e to return and Return OK; otherwise, an error is returned.
If (S. Top = S. Base)
Return Error;
E = * -- S. Top;
Return OK;
} // Pop
Status destroystack (stack & S) {// destroy stack s
Free (S. Base );
S. Top = S. base;
Return OK;
} // Destroystack