Data Structure Stack: Infix to Postfix
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的更多相关文章
- uva 11995 I Can Guess the Data Structure stack,queue,priority_queue
题意:给你n个操做,判断是那种数据结构. #include<iostream> #include<cstdio> #include<cstdlib> #includ ...
- [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 ...
- Data Structure Stack: Reverse a stack using recursion
http://www.geeksforgeeks.org/reverse-a-stack-using-recursion/ #include <iostream> #include < ...
- HDU5739 Fantasia(点双连通分量 + Block Forest Data Structure)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5739 Description Professor Zhang has an undirect ...
- hdu-5929 Basic Data Structure(双端队列+模拟)
题目链接: Basic Data Structure Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 65536/65536 K (Ja ...
- 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 ...
- HDU 5929 Basic Data Structure 模拟
Basic Data Structure Time Limit: 7000/3500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
- 【暑假】[实用数据结构]UVa11995 I Can Guess the Data Structure!
UVa11995 I Can Guess the Data Structure! 思路:边读边模拟,注意empty的判断! 代码如下: #include<iostream> #inclu ...
- CDOJ 483 Data Structure Problem DFS
Data Structure Problem Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/proble ...
随机推荐
- C#代码用法
1.new的用法using System;using System.Collections.Generic;using System.Text;namespace yanz{public class ...
- ie8下面版本号(包含ie8)的浏览器不支持html5标签属性解决方式(Modernizr 2.6.2插件的使用)
我这边申明下:我写这篇日志主要是想然ie8可以支持html5的个别标签闭合,并不能让ie全然支持html5.我之前写的可能会误导非常多同学.希望大家能明确. 今天脑抽想用html5标签设计一个网页.我 ...
- window 效率神器:Wox
官方网站 http://www.getwox.com/ 下载后以管理员身份运行,右下角可以看到Wox的图标.点击setting可以进入主界面 如果看不懂可以将语言设置为中文 默认快捷键是Alt + s ...
- Django--登录认证
COOKIE 与 SESSION 概念 cookie的使用,不止局限于我们所使用的登录认证,cookie不属于http协议范围,由于http协议无法保持状态,但实际情况,我们却又需要“保持状态”,因此 ...
- DataUml Design 教程1-初识
DataUml Design 是面向开发人员使用的一个永久免费的软件,提高软件的开发效率和代码的规范度.它主要包括三大功能,数据模型.代码生成和UML建模,数据模型功能类似于PowerDesi ...
- 怎样查看Eclipse是32位还是64位?
怎样查看Eclipse是32位还是64位? 1.去Eclipse的安装文件夹,找到eclipse.ini 2.打开这个文件.寻找:launcher.library,我的机器上,在第二行 3.查看&qu ...
- Android Studio SDK Manager 解决无法更新问题
一.首先要保证你可以FQ上google等网站. 这个..如何越过GFW就要靠自己了..网上也有很多教程.. 二.更改android sdk manager的option设置 选择Tools→Opini ...
- 09 nginx Rewrite(重写)详细解析
一:Rewrite(重写)详细解析 rewrite 重写 重写中用到的指令 if (条件) {} 设定条件,再进行重写 set #设置变量 return #返回状态码 break #跳出rewri ...
- 工具类之Condition
再次看到Condition,第一感觉还是觉得它和Mutex的功能是一样的,没必要存在.心里这么想,其实自己也知道怎么可能多余呢?老老实实的再分析一下代码,这次一定要把理解出来的内容记下来!都怪平时写代 ...
- eclipse导入web工程变成Java工程,解决方案
经常在eclipse中导入web项目时,出现转不了项目类型的问题,导入后就是一个java项目. 解决步骤: 1.进入项目目录,可看到.project文件,文本编辑器打开. 2.找到<nature ...