括号匹配
的有关信息介绍如下:
下面是我写的程序:你自己作个参考 :#include#include#include#includetypedef char ElemType;typedef struct stack{ ElemType data; struct stack *top;}LinkStack;int InitStack(LinkStack *&ls){ ls=NULL; return 1;}int ClearStack(LinkStack *&ls){ LinkStack *p; if(ls==NULL) return 0; while(ls!=NULL) { p=ls; ls=p->top; free(p); } return 1;}int StackEmpty(LinkStack *ls){ if(ls==NULL) return 1; else return 0;}int StackLength(LinkStack *ls){ int i=0; LinkStack *p=ls; while(p!=NULL) { p=p->top; i++; } return i;}ElemType GetTop(LinkStack *ls){ ElemType e; if(ls==NULL) return 0; e=ls->data; return e;}int Push(LinkStack *&ls,ElemType e){ LinkStack *p; p=new struct stack[sizeof(LinkStack)]; p->data=e; p->top=ls; ls=p; return 1;}int Pop(LinkStack *&ls,ElemType &e){ LinkStack *p; if(ls==NULL) return 0; else { p=ls; e=p->data; ls=p->top; free(p); } return 1;}//8. 访问栈中元素void StackPrint(LinkStack *ls){ LinkStack *p=ls; if(ls==NULL) return ; while(p!=NULL) { cout<data<<" "; p=p->top; }}//9. 写一算法,利用栈操作判断一字符串是否是回文。int huiwen(ElemType str[]){ int i=0; ElemType ch,temp; LinkStack *ls; InitStack(ls); while((ch=str[i++])!='\0') Push(ls,ch); i=0; while(!StackEmpty(ls)) { Pop(ls,temp); if(temp!=str[i++]) return 0; } return 1;}//10. 利用栈的基本信息,编写一个算法输入若干整数,以0标识输入结束。然后按与输入相反的次序输出这些数。int Reverse(){ ElemType ch; LinkStack *ls; InitStack(ls); cout<<"请输入你要输入的整数:"; cin>>ch; while(ch!=48) { Push(ls,ch); cin>>ch; } while(!StackEmpty(ls)) { Pop(ls,ch); cout< 版权声明:文章由 去问问 整理收集,来源于互联网或者用户投稿,如有侵权,请联系我们,我们会立即处理。如转载请保留本文链接:https://www.qwenw.com/article/343236.html