Stack implementation file C Language

Source: Internet
Author: User

/* Stack_adt.c -- stack model implementation file */<br/> # include <stdio. h> <br/> # include <stdlib. h> <br/> # include "stack_adt.h" </P> <p>/* local function declaration */</P> <p> static stack_node * make_node (const name * const panme ); </P> <p>/* interface function definition */</P> <p> int initializestack (stack * const pstack) <br/> {<br/> * pstack = (stack_node *) malloc (sizeof (stack_node); <br/> If (null = * pstack) <br/> return 0; <br/> else <br/>{< br/> * pstack = NULL; <br/> return 1; <br/>}</P> <p> int stackisempty (const stack * const pstack) <br/>{< br/> return null = * pstack; <br/>}</P> <p> int push (stack * const pstack, const name * const pname) <br/>{< br/> stack_node * new_node; </P> <p> new_node = make_node (pname ); <br/> If (new_node) <br/>{< br/> new_node-> next = * pstack; <br/> * pstack = new_node; <br/> return 1; <br/>}< br/> else <br/> return 0; <br/>}</P> <p> int POP (stack * const pstack, name * const pname) <br/>{< br/> stack_node * temp; </P> <p> If (stackisempty (pstack) <br/> return 0; <br/> else <br/> {<br/> * pname = (* pstack)-> name; <br/> temp = * pstack; <br/> * pstack = (* pstack)-> next; <br/> free (temp); <br/> return 1; <br/>}</P> <p> void traversal (const stack * const pstack, void (* pfun) (const stack_node * const stack_node )) <br/> {<br/> stack_node * scan = * pstack; </P> <p> while (SCAN) <br/>{< br/> (* pfun) (SCAN); <br/> scan = scan-> next; <br/>}</P> <p> void releasestack (const stack * const pstack) <br/>{< br/> stack_node * temp, * scan = * pstack; </P> <p> while (SCAN) <br/> {<br/> temp = scan; <br/> scan = scan-> next; <br/> free (temp ); <br/>}</P> <p>/* local function definition */</P> <p> static stack_node * make_node (const name * const pname) <br/> {<br/> stack_node * new_node; </P> <p> new_node = (stack_node *) malloc (sizeof (stack_node )); <br/> If (new_node) <br/>{< br/> new_node-> name = * pname; <br/>}</P> <p> return new_node; <br/>}

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.