首页 include

include

举报
开通vip

include#include #define MaxLen 100 int tran(char str[], char expr[]) //将中缀表达式转换成后缀表达式 { int st[100]; //转化过程使用的过度栈 char ch; int i=0,exindex=0,stindex=-1; //i是str下标,exindex是expr下标,stindex是st下标 while((ch=str[i++])!='\0') { if(ch>='0' && ch='0' && ch=0 && st[stindex]!='(...

include
#include #define MaxLen 100 int tran(char str[], char expr[]) //将中缀 关于同志近三年现实表现材料材料类招标技术评分表图表与交易pdf视力表打印pdf用图表说话 pdf 达式转换成后缀表达式 { int st[100]; //转化过程使用的过度栈 char ch; int i=0,exindex=0,stindex=-1; //i是str下标,exindex是expr下标,stindex是st下标 while((ch=str[i++])!='\0') { if(ch>='0' && ch<='9') //判断是数字 { expr[exindex]=ch; //压栈 exindex++; //栈顶指针上移 while((ch=str[i++])!='\0' && ch>='0' && ch<='9') //其它位依次入栈 { expr[exindex]=ch; exindex++; } i--; //str原算术表达式栈向下遍历 expr[exindex]='#'; //以特殊字符“#”表示结束 exindex++; } else if(ch=='(') //判断为左括号 { stindex++; st[stindex]=ch; } else if(ch==')') //判断为右括号 { while (st[stindex]!='(') { expr[exindex]=st[stindex]; stindex--; //依次弹出 exindex++; } stindex--;//'('出栈 } else if(ch=='+' || ch=='-')//判断为加减号 { while(stindex>=0 && st[stindex]!='(') { expr[exindex]=st[stindex]; stindex--; exindex++; } stindex++; st[stindex]=ch; } else if (ch=='*' || ch=='/')//判断为乘除号 { while(st[stindex]=='*' || st[stindex]=='/') { expr[exindex]=st[stindex]; stindex--; exindex++; } stindex++; st[stindex]=ch; } } while (stindex>=0)//将栈中所有运算符依次弹出存入expr栈中 { expr[exindex]=st[stindex]; exindex++; stindex--; } expr[exindex]='\0'; return 1; } int compvalue(char expr[],int *n) { int st[100],d; //st为数栈 char ch; int exindex=0,stindex=-1; //exindex是expr下标,stindex是st的下标 while((ch=expr[exindex++])!='\0') { if(ch>='0'&&ch<='9')//将数字字符转换成数字 { d=0; do { d=10*d+ch-'0'; } while((ch=expr[exindex++])!='#'); stindex++; st[stindex]=d;//数字进栈 } else//运算符操作 { switch(ch) { case'+':st[stindex-1]=st[stindex-1]+st[stindex]; break; case'-':st[stindex-1]=st[stindex-1]-st[stindex]; break; case'*':st[stindex-1]=st[stindex-1]*st[stindex]; break; case'/': if(st[stindex]!=0) { st[stindex-1]=st[stindex-1]/st[stindex]; } else return 0; //除0错误! break; } stindex--; } } (*n)=st[stindex]; return 1; } void main() { char str[100]; //存储原来算术表达式 char expr[100]; //存储转换成的后缀表达式 int n; cout<<"输入算术表达式:"<>str; if(tran(str,expr)==0) { cout<<"原算术表达式不正确!"<
本文档为【include】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_313140
暂无简介~
格式:doc
大小:24KB
软件:Word
页数:0
分类:互联网
上传时间:2011-10-12
浏览量:6