// The following is the C language implementation of the sequence stack, which is selected from data structure (C language description), Xu xiaokai, He Guiying, and Tsinghua University Press.
# Include "stdafx. H"
# Include <stdlib. h>
// The initial length is 100
# Define stacksize 100
Typedef char datatype;
Typedef struct stack {
Datatype data [stacksize];
Int top;
} Sqstack;
// Initialize the stack
Void initstack (sqstack * s)
{
S-> Top =-1;
}
// Judge whether it is null
Int stackempty (sqstack * s)
{
Return S-> Top =-1;
}
// Determine whether the stack is full
Int stackfull (sqstack * s)
{
Return S-> Top = StackSize-1;
}
// Stack entry
Void push (sqstack * s, datatype D)
{
If (stackfull (s ))
{
Printf ("Stack is full! ");
Exit (-1 );
}
S-> data [++ S-> top] = D;
}
// Output Stack
Datatype POP (sqstack * s)
{
If (stackempty (s ))
{
Printf ("Stack is empty! \ N ");
Exit (-1 );
}
Return (S-> data [S-> top --]);
}
// Display
Void disp (sqstack * s)
{
If (stackempty (s ))
{
Printf ("Stack is empty! \ N ");
Exit (-1 );
}
Int COUNT = s-> top;
Printf ("the elements of stack are: \ n ");
While (S-> top! =-1)
{
Printf ("% C \ n", S-> data [S-> top --]);
}
S-> Top = count;
}
Int main ()
{
Sqstack * s;
S = (sqstack *) malloc (sizeof (sqstack ));
Printf ("initialize the stack. \ n ");
Initstack (s );
Push (S, 'A ');
Push (S, 'B ');
Push (S, 'C ');
Push (S, 'd ');
Disp (s );
Printf ("pop a element \ n ");
Datatype AA = POP (s );
Disp (s );
Datatype BB = POP (s );
Disp (s );
Datatype cc = POP (s );
Disp (s );
Datatype dd = POP (s );
Disp (s );
Datatype EE = POP (s );
Disp (s );
Return 1;
}