Listing 2 This code fragment comes from a program containing a complex algorithm that needs a stack. The four functions are called at appropriate places by the main traversal code.
int StackPtr; StackElemTyp Stack [ StackMax ]; void Init ( ) { StackPtr = -1; } void Push ( Elem ) StackElemTyp Elem; { /* Check overflow here. */ Stack [ ++ StackPtr ] = Elem; } StackElemTyp Pop ( ) { assert ( StackPtr >= 0 ) return Stack [ StackPtr -- ]; } void CheckEmpty ( ) { assert ( StackPtr = -1 ) } /* End of File */