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. POI 实现合并单元格以及列自适应宽度

    POI是apache提供的一个读写Excel文档的开源组件,在操作excel时常要合并单元格,合并单元格的方法是: sheet.addMergedRegion(new CellRangeAddress ...

  2. 快速自检电脑是否被黑客入侵过(Linux版)

    前言 严谨地说, Linux只是一个内核, `GNU Linux`才算完整的操作系统, 但在本文里还是用通俗的叫法, 把`Ubuntu`,`Debian`,`RedHat`,`CentOS`,`Arc ...

  3. PHP将多级目录打包成zip文件

    最近接触PHP,需要用到zip压缩,在网上搜索的一大堆,发现代码都不低于50行.  而且调用还很费事(基础太少看不懂).让我收获的是Php提供有一个ZipArchive类,并有如下方法. bool a ...

  4. Ubuntu配置apache2.4配置虚拟主机遇到的问题

    update: 偶然看到了 apache的更新说明,直接贴个地址过来吧. http://httpd.apache.org/docs/2.4/upgrading.html 最近想把web开发目录从/va ...

  5. NPTL LinuxThreads

    Linux 线程模型的比较:LinuxThreads 和 NPTL 进行移植的开发人员需要了解的关键区别摘要 Vikram Shukla 2006 年 8 月 28 日发布 WeiboGoogle+用 ...

  6. 【Python学习】之yagmail库实现发送邮件

    上代码: import yagmail sendmail = 'xxx@126.com' sendpswd = 'xxx' receivemail = 'xxx@qq.com' # 连接邮箱服务器 y ...

  7. Mac OS X 安装Ruby

    安装CocoaPods第一步 起因:重装系统后需要重新安装CocoaPods网上搜了下发现很多都过时了,已经不能用了.而且taobao Gems源已经停止服务,现在有ruby-china提供服务 PS ...

  8. 推荐扔物线的HenCoder Android 开发进阶系列 后期接着更新

    官网地址:http://hencoder.com/ 我来做一次辛勤的搬运工 HenCoder:给高级 Android 工程师的进阶手册 HenCoder Android 开发进阶: 自定义 View ...

  9. 录音整理文字工具otranscribe简介

    网址: http://otranscribe.com/ 首先载入音频文件,支持 mp3, ogg, webm, wav (HTML5 无需将文件上传至服务器,可保护隐私),然后就可以边听边整理了. 通 ...

  10. WPF编程学习——样式(好文)

    http://www.cnblogs.com/libaoheng/archive/2011/11/20/2255963.html