Application of Stacks

Source: Internet
Author: User

1#include <stdio.h>2#include <stdlib.h>3typedefCharDatetype;4typedefstructStacknode5 {6 Datetype date;7     structStacknode *Next;8 }stacknode;9typedefstruct Ten { OneStacknode *top;/*stack Top pointer*/ A }linkstack; -  - voidInitstack (Linkstack *s)/*Initialize stack operation*/ the { -s->top==NULL; - } -  + intStackempty (Linkstack *s)/*Judging the stack empty operation*/ - { +     if(s->top==NULL) A         return 1; at     Else -         return 0; - } -  - intPush (Linkstack *s,datetype *x) - { inStacknode *p; -p= (Stacknode *)malloc(sizeof(Stacknode));/*Create a new node*/ to     if(p==NULL) +         return 0; -     Else the     { *p->date=x;/*put x in the data field of the new node*/ $p->next=s->top;/*Insert a new node before the list header*/Panax Notoginsengs->top=p;/*new node as the top of the stack.*/ -         return 1; the     } + } A  the intPop (Linkstack *s) + { -Stacknode *p; $ Datetype x; $     if(Stackempty (s)) -     { -printf"Stack Empty"); the         return 0; -     }Wuyi     Else the     { -P=s->top; WuX=p->date; -S->top=p->Next; About          Free(p); $         returnx; -     } - } -  A intMain () + { the Linkstack S; - Datetype x; $Initstack (&s); theprintf"Stack element:\n"); the      while((X=getchar ())! ='\ n') the     { thePush (&s,&x); -     } in      while(!stackempty (&s)) the     { theprintf"%c", Pop (&s)); About     } the}

Application of Stacks

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.