http://geeksquiz.com/stack-set-2-infix-to-postfix/

 #include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <fstream>
#include <map>
#include <set>
using namespace std; bool isoprand(char x) {
return x >= 'A' && x <= 'Z' || x >= 'a' && x <= 'z';
} int prec(char x) {
if (x == '+' || x == '-') return ;
if (x == '*' || x == '/') return ;
if (x == '^') return ;
return -;
} int infixtopostfix(string s) {
string ans;
stack<char> T;
for (int i = ; i < s.size(); i++) {
if (isoprand(s[i])) ans += s[i];
else if (s[i] == '(') T.push(s[i]);
else if (s[i] == ')') {
while (!T.empty() && T.top() != '(') {
ans += T.top();
T.pop();
}
if (!T.empty() && T.top() != '(') return -;
T.pop();
}
else {
while (!T.empty() && prec(s[i]) <= prec(T.top())) {
ans += T.top();
T.pop();
}
T.push(s[i]);
}
}
while (!T.empty()) {
ans += T.top();
T.pop();
}
cout << ans << endl;
} int main() {
string s = "a+b*(c^d-e)^(f+g*h)-i";
infixtopostfix(s);
return ;
}

Data Structure Stack: Infix to Postfix的更多相关文章

  1. uva 11995 I Can Guess the Data Structure stack,queue,priority_queue

    题意:给你n个操做,判断是那种数据结构. #include<iostream> #include<cstdio> #include<cstdlib> #includ ...

  2. [Data Structure] Stack Implementation in Python

    We can realize a Stack as an adaptation of a Python List. S.push(e)=L.append(e) S.pop()=L.pop() S.to ...

  3. Data Structure Stack: Reverse a stack using recursion

    http://www.geeksforgeeks.org/reverse-a-stack-using-recursion/ #include <iostream> #include < ...

  4. HDU5739 Fantasia(点双连通分量 + Block Forest Data Structure)

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5739 Description Professor Zhang has an undirect ...

  5. hdu-5929 Basic Data Structure(双端队列+模拟)

    题目链接: Basic Data Structure Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 65536/65536 K (Ja ...

  6. UVa 11995:I Can Guess the Data Structure!(数据结构练习)

    I Can Guess the Data Structure! There is a bag-like data structure, supporting two operations: 1 x T ...

  7. HDU 5929 Basic Data Structure 模拟

    Basic Data Structure Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

  8. 【暑假】[实用数据结构]UVa11995 I Can Guess the Data Structure!

    UVa11995  I Can Guess the Data Structure! 思路:边读边模拟,注意empty的判断! 代码如下: #include<iostream> #inclu ...

  9. CDOJ 483 Data Structure Problem DFS

    Data Structure Problem Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/proble ...

随机推荐

  1. 使用Maven整合SSH总结

    本人自己进行的SSH整合,中间遇到不少问题,特此做些总结,仅供参考. 项目环境: struts-2.3.31 + spring-4.3.7 + hibernate-4.2.21 + maven-3.3 ...

  2. 浅析Java语言中两种异常的差别

    Java提供了两类主要的异常:runtime exception和checked exception.所有的checked exception是从java.lang.Exception类衍生出来的,而 ...

  3. DOM概念的区分:Attribute和Property, html()及.text(), .val()

    Attribute就是dom节点自带的属性 例如:html中常用的id.class.title.align等: <div id="immooc" title="慕课 ...

  4. 监听EditText字数

    editContent.addTextChangedListener(new TextWatcher() { private CharSequence temp;private int editSta ...

  5. redis 的安装与启动

    1.redis介绍 Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,并提供多种语言的API. Redis 是一个高性能的key-val ...

  6. java之JDK动态代理

    © 版权声明:本文为博主原创文章,转载请注明出处 JDK动态代理: JDK动态代理就是在程序运行期间,根据java的反射机制自动的帮我们生成相应的代理类 优势: - 1. 业务类只需要关注业务逻辑本身 ...

  7. PyQt5 GUI Programming With Python 3.6 (一)

    PyQt5 PyQt5是一个基于强大的图形程式框架Qt5的python接口, 主要包含以下几个大类: ● QtCore ● QtGui ● QtWidgets ● QtMultimedia ● QtB ...

  8. oracle中提高order by的性能

    1.如果order by columnA,那么在where查询条件中添加条件columnA=value,则oracle内部会过滤order by排序,直接用索引(可以通过execution plan查 ...

  9. [ERROR] Error generating R.java from manifest

    把*.js文件用记事本打开,再保存为utf-8的编码覆盖,把build文件夹的文件删掉,启动.可以运行了.(在这之前试过把jdk的几个文件考到平台工具下的动作)

  10. Java学习笔记之equals和Objects.equals

    equals 相信大家就知道,就是比较,我们平时也会在自己定义的类中加入自己重写的equals用来比较两个类是否相同,例如这样 public class Person { private String ...