#include <stdio.h>#include <malloc.h>#include <string.h>#define maxsize 100typedef char datatype;typedef struct { datatype data[maxsize]; int top;}seqstack;void SetNull(seqstack *s)//置空堆疊{ s->top=-1;}int Empty(seqstack *s)//判斷堆疊是否為空{ if(s->top>=0) return false; else return true;}seqstack * Push(seqstack *s, datatype x)//壓入堆疊{ if(s->top==maxsize-1) { printf("overflow"); return NULL; } else { s->top++; s->data[s->top]=x; } return s;}datatype Pop(seqstack *s)//彈出函式{ if(Empty(s)) { printf("underflow"); return NULL; } else { s->top--; return(s->data[s->top+1]); }}datatype Top(seqstack *s)//取堆疊頂元素{ if(Empty(s)) { printf("underflow"); return NULL; } else return(s->data[s->top]);}void Show(seqstack *s)//顯示堆疊元素{ int i; printf("%c <--TOP\n",s->data[s->top]); for(i=s->top-1;i>=0;i--) { printf("%c\n",s->data[i]); } printf("\n");}bool String_SYM(char *string, int len,seqstack *s)//判斷字串中心對稱{bool Express(char *string,int len)//判斷運算式的括號是否合法{ //在此完成判斷運算式的括號是否合法}void main()//主函式{ char string[50]; int len; printf("請輸入一個字串(長度不超過50):"); scanf("%s",string); len=strlen(string); if(String_SYM(string,len)) printf("%s 有中心對稱關系\n",string); else printf("%s 沒有中心對稱關系\n",string); printf("請輸入一個expression(長度不超過50):"); scanf("%s",string); len=strlen(string); if(Express(string,len)) printf("\n公式'%s' 中的括號合法\n",string); else printf("\n公式'%s' 中的括號不合法\n",string);}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/117557.html
標籤:基礎類
下一篇:新手報到
