- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
运用栈方法的四则运算法(Four operations algorithm using stack method)
运用栈方法的四则运算法(Four operations algorithm using stack method)
算法一
# includes stdio.h
# includes math.h
# define maxsize 100
typedef struct
{
double date [maxsize];
int top;
} seqstack, * pseqstack 数据栈; / * * /
typedef struct
{
char date1 (maxsize];
int top1;
} seqstack1, * pseqstack1 字符栈; / * * /
void push (pseqstack d, double x)
入数据栈 {/ * * /
s - top + +;
s - date [s - top] = x;
}
double pop (pseqstack d)
出数据栈 {/ * * /
double x;
x = s - (s - [top];
s - top -.
return x;
}
void destory _ stack (pseqstack * s)
摧毁栈 {/ * * /
if (* s)
free (* 5);
* s = null;
return;
}
void push1 (pseqstack1 d, char x)
入字符栈 {/ * * /
s - top1 + +;
s - - top1 date1 [d] = x;
}
char pop1 (pseqstack1 d)
出字符栈 {/ * * /
char x;
x = s - - top1 date1 [d].
s - top1 - -;
return x;
}
char get _ top (pseqstack1 d)
取字符栈顶 {/ * * /
char x;
x = s - - top1 date1 [d].
return x;
}
int isnum (char ch)
判断是否为数字 {/ * * /
if (ch = 0 ch = 9)
return 1;
else
return 0;
}
int priority (char op)
求优先级 {/ * * /
switch (po).
{
houses = :
houses).
homes is #: return 1;
case +:
houses -: return 1;
case * * *:
houses /: return 1;
houses (: return 4.
}
}
double calculator (char [])
计算表达式 {/ * * /
int i = 0, j;
double int _ part = 0, float _ part = 0, x = 0;
double c, result, d, b;
char ch;
pseqstack s = (pseqstack) malloc (sizeof (seqstack)); / * 数据栈 * /
pseqstack1 k = (pseqstack1) malloc (sizeof (seqstack1)); / * 运算符栈 * /
s - top = - 1.
k - top1 = - 1.
push1 (k, #).
while (a [i]. = = = = | | (ch = get _ top (k)). = #)
{
if (isnum ([]) 当前字符为数字) / * * /
{
x = 0, int _ part = 0; float _ part = 0;
while (a [i]. =. isnum ([]))
{
int _ part = int _ part * 10 + [i] - 0.
the + +;
}
j = - 1;
if (a [i] = =.)
{
the + +;
while (isnum ([]))
{
float float _ _ part = part + ([i] (0) * pow (10, j).
the + +;
j -.
}
}
x = int _ part + float _ part;
push (s, x);
}
当前字符为运算符 else / * * /
if (a [i]. = )
{
if ((get _ top (k) = ( [i]. =)) | | priority (get _ top (k) priority (a [i]))
{push1 (k, 1); +;}
else
{
if (a [i] = =)
您可能关注的文档
- 主题活动《车子叭叭叭》案例设计及观察与反思(It seems theme car case design and observation and reflection).doc
- 花生油市场调研(Peanut oil Market Research).doc
- 黑豆果栽培技术(Cultivation techniques of black bean fruit).doc
- 中译英训练(Chinese English translation training).doc
- 主题医院攻略(Theme hospital introduction).doc
- 主题班会活动方案的设计(Design of activity program for theme class meeting).doc
- 黑龙江省生活饮用水卫生监督管理规定(Provisions on the supervision and administration of drinking water hygiene in Heilongjiang).doc
- 黑龙江省高等学校教师系列中高级专业技术职务任职资格评审标准--高职(Heilongjiang higher education teachers series of senior technical qualifications evaluation criteria - Higher Vocational).doc
- 默写常见的名句名篇(七)(Some common famous quote (seven)).doc
- 鼓山(GUSHAN).doc
- 运筹学与管理信息系统(Operations research and management information system).doc
- 运动训(Sports training).doc
- 近代自然科学的发展和经济发展历程txt(The development of modern natural science and the course of economic development TXT).doc
- 返乡农民工急需新工作(Migrant workers need new jobs).doc
- 还识字教学以精彩(Also literacy teaching to wonderful!).doc
- 近代美国科学(Modern American Science).doc
- 这些话说得太绝了,不收藏对不起我自己!(These words are too extreme, do not collect, sorry myself!).doc
- 这样学习c语言最有效(连载2)——趣味、通俗、实用的计算机达人成长之路之c语言高级技巧篇(In this way, learning C language is the most effective (Serial 2) - interesting, popular and practical computer, people grow up, C language, advanced skills, article.doc
- 这是本站收集的超(This is super collected by this station).doc
- 运用会话含义理论提高商务交际(Applying conversational implicature theory to improve business communication).doc
文档评论(0)