The array Stack has not been written for a long time. This write has deepened understanding and gained a deeper understanding of the skills and practicality in routines.
/* Stack. H -- stack header file */</P> <p> # define empty_top (-1) </P> <p>/* data type definition */</P> <p> typedef int stack_item; <br/> typedef struct stack <br/> {<br/> stack_item * array; <br/> int capacity; <br/> int top; <br/>} * stack; </P> <p>/* interface function declaration */</P> <p>/* operation: before creating and initializing a stack */<br/>/* operation: pstack points to a stack, and capacity is the variable indicating the stack size */<br/>/* operation: if capacity is a valid value range & memory allocation is successful, the stack is created and initialized as null. 1 is returned; otherwise, 0 */<br/>/* time complexity is returned: O (1) */<br/> int initialize_s (stack * const pstack, const int capacity ); </P> <p>/* operation: Check whether the stack is empty */<br/>/* before the operation: after pstack points to an initialized stack */<br/>/*: If the stack is empty, 1 is returned; otherwise, 0 */<br/>/* time complexity is returned: O (1) */<br/> int isempty_s (const stack * const pstack ); </P> <p>/* operation: Check whether the stack is full */<br/>/* before: after pstack points to an initialized stack */<br/>/*: If the stack is full, 1 is returned; otherwise, 0 */<br/>/* is returned: O (1) */<br/> int isfull_s (const stack * const pstack); </P> <p>/* operation: add two elements to the stack */<br/>/* before the operation: pstack points to an initialized stack, Si1, if the stack is not full, add the data to the stack and return 1; otherwise, 0 */<br/>/* time complexity is returned: O (1) */<br/> int push_s (const stack * const pstack, const stack_item ST1, const stack_item st2); </P> <p>/* operation: two elements are displayed from the stack */<br/>/* before the operation: pstack points to an initialized stack. After pst1 and pst2 point to two data pointers */<br/>/*: If the stack is not empty, two elements are popped up from the top of the stack to maintain the original relative order of the two, and 1 is returned; otherwise, 0 */<br/>/* time complexity: O (1) is returned) */<br/> int pop_s (const stack * const pstack, stack_item * const pst1, stack_item * const pst2); </P> <p>/* operation: release the memory space occupied by a stack */<br/>/* before the operation: pstack points to an initialized stack */<br/>/* after the operation: the memory space occupied by the stack is released */<br/>/* time complexity: O (1) */<br/> void release_s (const stack * const pstack );