欢迎来到天天文库
浏览记录
ID:47864493
大小:29.50 KB
页数:4页
时间:2019-08-05
《判断是否为回文》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、#include#include#include#include#includeusingnamespacestd;#defineTRUE1#defineFLASE0#defineOK1#defineERROR0#defineINFEASIBLE-1#defineOVERFLOW-2typedefintStatus;typedefcharSElemType;#defineSTACK_INIT_SIZE100;#defineSTACKINCREMENT10;typedefstruct{
2、SElemType*base;SElemType*top;intstacksize;}SqStack;StatusInitStack(SqStack&S){S.base=(SElemType*)malloc(100*sizeof(SElemType));//修改if(!S.base)exit(OVERFLOW);S.top=S.base;S.stacksize=STACK_INIT_SIZE;returnOK;}StatusGetTop(SqStackS,SElemType&e){if(S.top==S.base)returnERROR;e=*(S.top-1);return
3、OK;}StatusPush(SqStack&S,SElemTypee){if(S.top-S.base>=S.stacksize){S.base=(SElemType*)realloc(S.base,(S.stacksize+10)*sizeof(SElemType));//修改if(!S.base)exit(OVERFLOW);S.top=S.base+S.stacksize;S.stacksize+=STACKINCREMENT;}*S.top++=e;returnOK;}StatusPop(SqStack&S,SElemType&e){if(S.top==S.base
4、)returnERROR;e=*--S.top;returnOK;}StatusDestroyStack(SqStack&S){free(S.base);S.base=NULL;S.top=NULL;S.stacksize=0;returnOK;}StatusClearStack(SqStack&S){S.top=S.base;returnOK;}StatusStackEmpty(SqStackS){if(S.base==S.top)returnOK;elsereturnERROR;}StatusStackLength(SqStackS){intl;l=S.top-S.bas
5、e;returnl;}typedefcharQElemType;#defineMAXQSIZE100typedefstruct{QElemType*base;intfront;intrear;}SqQueue;StatusInitQueue(SqQueue&Q){Q.base=(QElemType*)malloc(MAXQSIZE*sizeof(QElemType));if(!Q.base)exit(OVERFLOW);Q.front=Q.rear=0;returnOK;}intQueueLength(SqQueueQ){return(Q.rear-Q.front+MAXQS
6、IZE)%MAXQSIZE;}StatusEnQueue(SqQueue&Q,QElemTypee){if((Q.rear+1)%MAXQSIZE==Q.front)returnERROR;Q.base[Q.rear]=e;Q.rear=(Q.rear+1)%MAXQSIZE;returnOK;}StatusDeQueue(SqQueue&Q,QElemType&e){if(Q.front==Q.rear)returnERROR;e=Q.base[Q.front];Q.front=(Q.front+1)%MAXQSIZE;returnOK;}Statusabc(strings
7、tr){SqStackS;InitStack(S);SqQueueQ;InitQueue(Q);chare1,e2;for(inti=0;str[i]!='@';i++){Push(S,str[i]);EnQueue(Q,str[i]);}while(!StackEmpty(S)){Pop(S,e1);DeQueue(Q,e2);if(e1!=e2)returnERROR;}returnOK;}voidmain(){stringstr;inta;printf("请输入一个字符序列,并以@为结束符:");
此文档下载收益归作者所有