符号平衡的算法.doc

  1. 1、本文档共5页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
符号平衡的算法

#include?stdio.h?? #include?stdlib.h?? #define?ElementType?char?? ?? ?? typedef?struct?Node?*PtrToNode;?? typedef?PtrToNode?Stack;?? typedef?struct?Node?? {?? ????ElementType?Element;?? ????PtrToNode?Next;?? };?? ?? int?IsEmpty(Stack?S);?? Stack?CreateStack();?? void?DisposeStack(Stack?S);?? void?MakeEmpty(Stack?S);?? void?Push(ElementType?X,Stack?S);?? ElementType?Top(Stack?S);?? void?Pop(Stack?S);?? ?? //判断栈是否为空?? int?IsEmpty(Stack?S)?? {?? ????return?S-Next?==?NULL;?? }?? //创建链栈?? Stack?CreateStack()?? {?? ????Stack?S?=?malloc(sizeof(struct?Node));?? ????if(S?==?NULL)?? ????{?? ????????printf(No?enough?memory!);?? ????????return?NULL;?? ????}?? ????S-Next?=?NULL;?? ????MakeEmpty(S);?? ????return?S;?? }?? ?? void?MakeEmpty(Stack?S)?? {?? ????if(S?==?NULL)?? ????{?? ????????printf(Use?CreateStack?First!);?? ????}?? ????else?? ????{?? ????????while(!IsEmpty(S))?? ????????{?? ????????????Pop(S);?? ????????}?? ????}?? }?? ?? void?Push(ElementType?X,Stack?S)?? {?? ????PtrToNode?Tmp;?? ????Tmp?=?malloc(sizeof(struct?Node));?? ????if(Tmp?!=?NULL)?? ????{?? ????????Tmp-Element?=?X;?? ????????Tmp-Next?=?S-Next;?? ????????S-Next?=?Tmp;?? ????}?? ????else?? ????{?? ????????printf(Out?of?space!);?? ????}?? }?? ?? void?Pop(Stack?S)?? {?? ?????? ????if(IsEmpty(S))?? ????{?? ????????printf(The?Stack?is?Empty!);?? ????}?? ????else?? ????{?? ????????PtrToNode?Tmp?=?S-Next;?? ????????S-Next?=?Tmp-Next;?? ????????free(Tmp);?? ????}?? }?? ?? ElementType?Top(Stack?S)?? {?? ????if(IsEmpty(S))?? ????{?? ????????printf(The?stack?is?empty!);?? ????????return?0;?? ????}?? ????else?? ????{?? ????????return?S-Next-Element;?? ????}?? }?? ?? //平衡符号判断?? void?balance(char?*ch,Stack?S)?? {?? ????ElementType?c;?? ????MakeEmpty(S);?? ????while((c=*ch)?!=?\0)?? ????{?? ????????printf(%c\n,c);?? ????????switch(c)?? ????????{?? ????????case?(:?? ????????case?[:?? ????????case?{:?? ????????????Push(c,S);?? ????????????break;?? ????????case?):?? ????????????if(IsEmpty(S))?? ????????????{?? ?????????????

文档评论(0)

haihang2017 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档