TA的每日心情 | 开心 2021-3-12 23:18 |
---|
签到天数: 2 天 [LV.1]初来乍到
|
栈的应用实例
一、中缀表达式转换为后缀表达式(只处理了+,-,*,/,(,))的代码:
运行结果:
C:xx>java InfixApp
Enter infix: a+b*(c-d)
For a Stack (bottom-->top):
For + Stack (bottom-->top):
For b Stack (bottom-->top): +
For * Stack (bottom-->top): +
For ( Stack (bottom-->top): + *
For c Stack (bottom-->top): + * (
For - Stack (bottom-->top): + * (
For d Stack (bottom-->top): + * ( -
For ) Stack (bottom-->top): + * ( -
While Stack (bottom-->top): + *
While Stack (bottom-->top): +
End Stack (bottom-->top):
Postfix is abcd-*+
二、求后缀表达式的值(只处理了一位数)
注:3-(4+5)=-6
源码下载:http://file.javaxxz.com/2014/10/30/235945687.zip |
|