%----------------------------------------------------------------
% Filename :Change.m
% Created by yufei 3504688775 at 8/7/2020
% Description :Implement the function of infix expression to suffix expression.
%----------------------------------------------------------------
function [str1] = Change(str)
str1='';
stack='#';
for i =1:length(str)
if str(i)==' '
continue;
end
if str(i)=='0'||str(i)=='1'||str(i)=='2'||str(i)=='3'||str(i)=='4'||str(i)=='5'||str(i)=='6'||str(i)=='7'||str(i)=='8'||str(i)=='9'
str1=[str1 str(i)];
end
if str(i)=='+'||str(i)=='-'
if length(stack)==1
stack(end+1)=str(i);
else
while 1
e=stack(end);
if e~='('&& length(stack)>1
str1=[str1 e];
stack(end)=[];
else
break;
end
end
stack(end+1)=str(i);
end
elseif str(i)==')'
while 1
e=stack(end);
if e~='('
str1=[str1 e];
stack(end)=[];
else
stack(end)=[];
break;
end
end
elseif str(i)=='('||str(i)=='*'||str(i)=='/'
stack(end+1)=str(i);
end
end
while 1
if length(stack)>1
e=stack(end);
str1=[str1 e];
stack(end)=[];
else
break;
end
end
end
中缀表达式转后缀表达式.zip
需积分: 18 34 浏览量
2020-08-07
16:46:51
上传
评论
收藏 2KB ZIP 举报
雨飞飞羽
- 粉丝: 497
- 资源: 11
最新资源
- 2023-04-06-项目笔记 - 第一百十五阶段 - 4.4.2.113全局变量的作用域-113 -2024.04.26
- 2023-04-06-项目笔记 - 第一百十五阶段 - 4.4.2.113全局变量的作用域-113 -2024.04.26
- htmlzwbjq_downyi.com.zip
- 无头单向非循环链表的实现(Test.c)
- 无头单向非循环链表的实现(SList.c)
- 浏览器重定向插件更新文件
- SSA-BP麻雀算法优化BP神经网络多特征分类预测(Matlab实现完整源码和数据)
- 粒子群算法优化BP神经网络PSO-BP的MATLAB代码(数值预测)
- 基于Springboot的一起看书平台.zip
- 无头单向非循环链表的实现(SList.h)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈