Stack Array Implementation header file C Language

Source: Internet
Author: User

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 );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.