


全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
#include#includestruct node / 栈结构声明int data; / 数据域 struct node *next; / 指针域;typedef struct node stacklist; / 链表类型typedef stacklist *link; / 链表指针类型link operand=NULL; / 操作数栈指针link push(link stack,int value) / 进栈 link newnode; / 新结点指针 newnode=new stacklist; / 分配新结点if (!newnode) printf(分配失败!); return NULL; newnode-data=value; / 创建结点的内容 newnode-next=stack; stack=newnode; / 新结点成为栈的开始return stack;link pop(link stack,int *value) / 出栈 link top; / 指向栈顶 if (stack !=NULL) top=stack; / 指向栈顶 stack=stack-next; / 移动栈顶指针 *value=top-data; / 取数据 delete top; / 吸收结点 return stack; / 返回栈顶指针 else *value=-1;int empty(link stack) / 判栈空 if (stack!=NULL) return 1; else return 0;int isoperator(char op) / 判运算符 switch (op) case+: case-: case*:return 1; / 是运算符,返回1 case/:return 0; / 不是运算符,返回0 int getvalue(int op,int operand1,int operand2) / 计算表达式值 switch(char)op) case*:return(operand1*operand2); case/:return(operand1/operand2); case+:return(operand1+operand2); case-:return(operand1-operand2); void main() / 主函数 char exp100; int operand1=0; / 定义操作数1 int operand2=0; / 定义操作数2 int result=0; / 定义操作结果 int pos=0; printf(tn 请输入后缀表达式:); gets(exp); / 读取表达式 printf(tnn 后缀表达式%s的计算结果是:,exp); while (exppos !=0 & exppos !=n) / 分析表达式字符串 if (isoperator(exppos) / 是运算符,取两个操作数 operand=pop(operand,&operand1); operand=pop(operand,&operand2); operand=push(operand,getvalue(exppos,operand1,operand2);/ 计算结果入栈 else operand=push(operand,exppos-48); / 是操作数,压入操作数栈 pos+;
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 厦门市保安考试试题及答案
- springcloud面试题总结及答案
- 皮皮鲁传考试题及答案
- 化工合成面试题及答案
- 土路汽车测试题及答案
- 风控部员工面试题及答案
- 广西单招试题及答案
- 临床医学专升本试题数学及答案2025版
- 临床医学编辑笔试题及答案2025版
- 药品召回管理办法及药品追溯培训专项测试题有答案
- 医院综合门诊部综合管理体系建设
- 2025年中医师承出师考试题库
- uom无人机考试题库及答案2025
- 预防接种基础知识课件
- 护栏生产及安装方案(3篇)
- 污水厂培训课件
- 陕西省专业技术人员继续教育2025公需课《党的二十届三中全会精神解读与高质量发展》20学时题库及答案
- 通信工程竣工资料模板(通用版)
- 中国半导体行业投资深度分析与展望
- 应急中心组织架构
- 教练技术探索课程一阶段导师讲义
评论
0/150
提交评论