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 ...
随机推荐
- Java + Selenium + WebDriver八大元素定位方式
UI自动化测试的第一步就是进行元素定位,下面给大家介绍一下Selenium + WebDriver的八大元素定位方式.现在我们就以百度搜索框为例进行元素定位,如下图: 一.By.name() Java ...
- 点击tablecell中的一个按钮,确定cell所在的行
- (void) del:(UIButton *) button { NSLog(@"%s",__FUNCTION__); UITableViewCell * cell = (UI ...
- 转 RabbitMQ
转自:https://blog.thankbabe.com/2017/08/03/rabbitmq-demo/?from=cnblogs 介绍 RabbitMQ是一个由erlang开发的基于AMQP( ...
- MyReport报表引擎2.7.8.8公布
支持嵌套子报表直接编辑保存,多个子报表同一时候存储在一个报表格式文件中,设计更简便,避免了嵌套报表的多个报表格式载入. watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5 ...
- SD--怎样增强是同一类出库单使用不同号码段
在现实的业务中,一个公司有多个销售组织,它们使用同一个出库类型,业务往往希望它们创建的出库单的号码採用不同号码范围.但在sap里出库单号码范围是在出库单类型里设置,也就是使用同样的出库单类型,也就使用 ...
- YUV格式学习汇总
本文为个人学习使用,部分内容摘自他人. 参考: https://www.cnblogs.com/ALittleDust/p/5935983.html http://www.cnblogs.com/az ...
- IIS8应用池重启脚本
重启 IIS8 应用程序池的批处理 批处理很简单:c:\windows\system32\inetsrv\AppCmd.exe stop apppool /apppool.name:"ASP ...
- 【Navicat Premium】之连接Oracle数据库
1.首先,在连接之前,需要下载oracle官网提供的instantclient-basic-win32-11.2.0.1.0.zip包 官网:http://www.oracle.com/technet ...
- .Net中多线程类的使用和总结
lock, Monitor, Thread, Join, BackGroundWorker. 消费者和生产者.Async 委托Invoke TypeHandle中BlockIndex. http: ...
- Oracle Data Provider for .NET的使用(二)-驱动更换与注意事项
上篇说过了ODP的安装与配置 ,但是个人比较喜欢托管类型的,毕竟非托管类型的,因为考虑到会有用户或者是服务器或者是开发人员有32位的机器,就要强制编译平台平台为32位,只因为这个驱动,有点让人不愉快了 ...