# Include <stdio. h>
# Include <string. h>
# Include <conio. h>
# Include <stdlib. h>
# Define STACK_INIT_SIZE 10
# Define OK 1
# Define TRUE 1
# Define FALSE 0
# Define ERROR 0
Char PASSWORD [10] = "abcdef";/* PASSWORD, global variable */
Typedef char SElemType;
Typedef struct STACK/* define STACK type */
{
SElemType * base;
SElemType * top;
Int stacksize;
Int length;
} SqStack, * Stack;
Typedef int Status;
Void InitStack (Stack * S)/* initialize Stack */
{
* S = (SqStack *) malloc (sizeof (SqStack ));
(* S)-> base = (SElemType *) malloc (STACK_INIT_SIZE * sizeof (SElemType ));
If (! (* S)-> base) exit (-1 );
(* S)-> top = (* S)-> base;
(* S)-> stacksize = STACK_INIT_SIZE;
(* S)-> length = 0;
}
Status DestroyStack (Stack * S)/* destroy Stack */
{
Free (* S)-> base );
Free (* S ));
Return OK;
}
Void ClearStack (Stack * S)/* empty Stack */
{
(* S)-> top = (* S)-> base;
(* S)-> length = 0;
}
Status StackEmpty (SqStack S)/* determine whether the stack is empty */
{
If (S. top = S. base) return TRUE;
Else
Return FALSE;
}
Void Push (Stack * S, SElemType e)/* Push data to Stack */
{
If (* S)-> top-(* S)-> base> = (* S)-> stacksize)
{
(* S)-> base = (SElemType *) realloc (* S)-> base,
(* S)-> stacksize + 2) * sizeof (SElemType ));
If (! (* S)-> base) exit (-1 );
(* S)-> top = (* S)-> base + (* S)-> stacksize;
(* S)-> stacksize + = 2;
}
* (* S)-> top ++) = e;
++ (* S)-> length;
}
Status Pop (Stack * S)/* Delete the top element of the Stack */
{
If (* S)-> top = (* S)-> base) return ERROR;
(* S)-> top --;
-- (* S)-> length;
Return OK;
}
Status GetTop (Stack S, SElemType * e)/* return the top element of the Stack */
{
If (S-> top = S-> base) return ERROR;
* E = * (S-> top-1 );
S-> top --;
}
Void Change (SqStack S, char * a)/* returns the elements in the stack to a in reverse order */
{Int n = S. length-1;
While (! StackEmpty (S ))
GetTop (& S, & a [n --]);
} <