#include<iostream>#include"ac.h"usingnamespace std;/* run this program using the console pauser or add your own getch, system("pause") or input loop */intmain(int argc,char** argv){
stack head ;while(1){printf("1.创建栈\n");printf("2.弹出栈顶元素\n");printf("3.压入元素\n");printf("4.遍历输出栈\n");printf("5.退出程序\n");printf("6.括号匹配\n");printf("请输入你的选择: ");int q ;scanf("%d",&q);switch(q){case1:{creatStack(head);break;}case2:{
Element e;if(popStack(head,e))printf("栈顶元素为:%c\n",e);break;}case3:{int cn;printf("请输入你要压入栈的元素个数\n");scanf("%d",&cn);getchar();for(int i =0; i < cn ; i ++){
Element s ;scanf("%c",&s);pushStack(head,s);}break;}case4:{print(head);break;}case5:{printf("退出程序\n");return0;break;}case6:{creatStack(head);
string s;getchar();printf("请输入一系列括号:");bool st =true;
cin>>s;for(int i =0; i < s.length(); i ++){if(s[i]=='('|| s[i]=='['|| s[i]=='{')pushStack(head,s[i]);char q;if((s[i]==')'|| s[i]==']'|| s[i]=='}')&&(!popStack(head,q)|| q +1!= s[i])){
st =false;}}if(!st)printf("括号不匹配!!\n");else{printf("括号匹配成功!!!\n");}break;}}}return0;}
#include<iostream>#include<malloc.h>#define Max 100usingnamespace std;typedefchar Element;typedefstruct stack
{
Element *top;
Element *base;int size;}stack;voidcreatStack(stack &head);intpopStack(stack &head , Element &e);voidpushStack(stack &head , Element e);voidprint(stack &head);