全文预览

数据结构课程设计 表达式求值【完整版】

上传者:似水流年 |  格式:doc  |  页数:18 |  大小:79KB

文档介绍
har*)realloc(s.base,(s.stacksize+5)*sizeof(char));//栈满的时候,追加5个存储空间if(!s.base)exit(OVERFLOW); s.top=s.base+s.stacksize;s.stacksize+=5;?}?*(s.top)++=e;//把e入栈?returnOK;}intPop(SqStack&s,char&e)//运算符出栈{?if(s.top==s.base)//栈为空栈的时候,返回ERROR?{?printf("运算符栈为空!\n");?returnERROR;?}else?{ e=*--s.top;//栈不为空的时候用e做返回值,删除S的栈顶元素,并返回OK returnOK;?}}intStackTraverse(SqStack&s)//运算符栈的遍历{?char*t;?t=s.base;?if(s.top==s.base)?{?printf("运算符栈为空!\n");//栈为空栈的时候返回ERROR?returnERROR;?}?while(t!=s.top)?{ printf("%c",*t);//栈不为空的时候依次取出栈内元素t++;?}returnERROR;}//**********************数字栈部分***************************structSqStackn//定义数栈{int*base;//栈底指针int*top;//栈顶指针intstacksize;//栈的长度};intInitStackn(SqStackn&s)//建立一个空栈S{s.base=(int*)malloc(50*sizeof(int));if(!s.base)exit(OVERFLOW);//存储分配失败s.top=s.base;s.stacksize=50;returnOK;}

收藏

分享

举报
下载此文档