/* ECP: FILEname=fig10_6.c */ /* 1*/ #include /* 2*/ #include /* 3*/ typedef Symbol StEtype; /* 4*/ typedef struct StackStr /* 5*/ { /* 6*/ StEtype *Array; /* The Array Of Elements */ /* 7*/ int TopOfStack; /* Index Of Top Element */ /* 8*/ int MaxSize; /* Maximum Stack Size */ /* 9*/ } *Stack; /*10*/ static const StInitSize = 5; /* 1*/ Stack /* 2*/ StMakeEmpty( Stack S ) /* 3*/ { /* 4*/ if( S == NULL ) /* 5*/ { /* 6*/ if( ! ( S = malloc( sizeof( struct StackStr ) ) ) ) /* 7*/ return NULL; /* 8*/ S->Array = malloc( sizeof( StEtype ) * StInitSize ); /* 9*/ if( S->Array == NULL ) /*10*/ return NULL; /*11*/ S->MaxSize = StInitSize; /*12*/ } /*13*/ S->TopOfStack = -1; /*14*/ return S; /*15*/ } /* 1*/ static void /* 2*/ StInsistGood( const Stack S ) /* 3*/ { /* 4*/ if( S == NULL ) /* 5*/ { /* 6*/ printf( "Stack routine received bad Stack\n" ); /* 7*/ exit( 1 ); /* 8*/ } /* 9*/ }